Skip to content
23 changes: 23 additions & 0 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,29 @@ impl Transform {
self.local_z()
}

/// Translates this [`Transform`] within its local space using the provided translation vector.
///
/// This method directly adjusts the [`Transform`]'s translation using the `translation` vector,
/// without considering the [`Transform`]'s current rotation. The translation happens in the
/// [`Transform`]'s local coordinate system, meaning the movement occurs along its local
/// axes (`x`, `y`, and `z`), regardless of the [`Transform`]'s orientation.
#[inline]
pub const fn translate(&mut self, translation: Vec3) {
self.translation += translation;
}

/// Translates this [`Transform`] within its local space, considering its rotation and orientation.
///
/// This method translates this [`Transform`] based on its current rotation, so the movement
/// happens relative to the direction this [`Transform`] is facing. The `translation` vector is
/// transformed by the [`Transform`]'s rotation, allowing for natural directional movement.
/// For instance, moving "forward" means moving along the [`Transform`]'s forward direction
/// based on its current orientation, rather than just along the local z-axis.
#[inline]
pub const fn translate_with_local_rotation(&mut self, translation: Vec3) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is way too verbose to me, I would just call this translate_local, matching the existing rotate_local. Godot also has Transform3D.translated_local

Suggested change
pub const fn translate_with_local_rotation(&mut self, translation: Vec3) {
pub const fn translate_local(&mut self, translation: Vec3) {

Copy link
Contributor

@Jondolf Jondolf Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the downside is that one could expect a "local translation" to also consider scale (Godot's does afaik), which translate_with_local_rotation shouldn't do.

But idk I'd rather just manually do transform.translate(transform.rotation * local_translation) than use the long name and do transform.translate_with_local_rotation(local_translation), but that's probably a me-problem 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my personal preference here would probably be having translate and translate_local, where the latter is with respect to the local frame, considering both rotation and scale. If you only want to consider rotation, then you can just do transform.translate(transform.rotation * local_translation).

self.translation += self.rotation * translation;
}

/// Rotates this [`Transform`] by the given rotation.
///
/// If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent.
Expand Down
3 changes: 1 addition & 2 deletions examples/transforms/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ fn move_cube(mut cubes: Query<(&mut Transform, &mut Movable)>, timer: Res<Time>)
if (cube.spawn - transform.translation).length() > cube.max_distance {
cube.speed *= -1.0;
}
let direction = transform.local_x();
transform.translation += direction * cube.speed * timer.delta_seconds();
transform.translate(Vec3::X * cube.speed * timer.delta_seconds());
}
}