Skip to content

Commit b060e16

Browse files
committed
Add synonyms for transform relative vectors (#1667)
Fixes #1663. I think the directions are correct (same as [here](https://docs.godotengine.org/en/stable/classes/class_vector3.html?highlight=forward#constants)), but please double check because I might have mixed them up. Co-authored-by: guimcaballero <[email protected]> Co-authored-by: Guim Caballero <[email protected]>
1 parent 6ce57c8 commit b060e16

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

crates/bevy_transform/src/components/global_transform.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,54 @@ impl GlobalTransform {
118118
self.rotation * Vec3::X
119119
}
120120

121+
/// Equivalent to -local_x()
122+
#[inline]
123+
pub fn left(&self) -> Vec3 {
124+
-self.local_x()
125+
}
126+
127+
/// Equivalent to local_x()
128+
#[inline]
129+
pub fn right(&self) -> Vec3 {
130+
self.local_x()
131+
}
132+
121133
/// Get the unit vector in the local y direction
122134
#[inline]
123135
pub fn local_y(&self) -> Vec3 {
124136
self.rotation * Vec3::Y
125137
}
126138

139+
/// Equivalent to local_y()
140+
#[inline]
141+
pub fn up(&self) -> Vec3 {
142+
self.local_y()
143+
}
144+
145+
/// Equivalent to -local_y()
146+
#[inline]
147+
pub fn down(&self) -> Vec3 {
148+
-self.local_y()
149+
}
150+
127151
/// Get the unit vector in the local z direction
128152
#[inline]
129153
pub fn local_z(&self) -> Vec3 {
130154
self.rotation * Vec3::Z
131155
}
132156

157+
/// Equivalent to -local_z()
158+
#[inline]
159+
pub fn forward(&self) -> Vec3 {
160+
-self.local_z()
161+
}
162+
163+
/// Equivalent to local_z()
164+
#[inline]
165+
pub fn back(&self) -> Vec3 {
166+
self.local_z()
167+
}
168+
133169
#[doc(hidden)]
134170
#[inline]
135171
pub fn rotate(&mut self, rotation: Quat) {

crates/bevy_transform/src/components/transform.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,54 @@ impl Transform {
130130
self.rotation * Vec3::X
131131
}
132132

133+
/// Equivalent to -local_x()
134+
#[inline]
135+
pub fn left(&self) -> Vec3 {
136+
-self.local_x()
137+
}
138+
139+
/// Equivalent to local_x()
140+
#[inline]
141+
pub fn right(&self) -> Vec3 {
142+
self.local_x()
143+
}
144+
133145
/// Get the unit vector in the local y direction.
134146
#[inline]
135147
pub fn local_y(&self) -> Vec3 {
136148
self.rotation * Vec3::Y
137149
}
138150

151+
/// Equivalent to local_y()
152+
#[inline]
153+
pub fn up(&self) -> Vec3 {
154+
self.local_y()
155+
}
156+
157+
/// Equivalent to -local_y()
158+
#[inline]
159+
pub fn down(&self) -> Vec3 {
160+
-self.local_y()
161+
}
162+
139163
/// Get the unit vector in the local z direction.
140164
#[inline]
141165
pub fn local_z(&self) -> Vec3 {
142166
self.rotation * Vec3::Z
143167
}
144168

169+
/// Equivalent to -local_z()
170+
#[inline]
171+
pub fn forward(&self) -> Vec3 {
172+
-self.local_z()
173+
}
174+
175+
/// Equivalent to local_z()
176+
#[inline]
177+
pub fn back(&self) -> Vec3 {
178+
self.local_z()
179+
}
180+
145181
/// Rotates the transform by the given rotation.
146182
#[inline]
147183
pub fn rotate(&mut self, rotation: Quat) {

0 commit comments

Comments
 (0)