refactor signature of methods to accept single vec3

This commit is contained in:
Alessandro Esposito 2024-09-15 11:10:49 +02:00
parent 7cab110449
commit 5c4228d22c
2 changed files with 22 additions and 22 deletions

View file

@ -288,35 +288,35 @@ impl Transform {
self.local_z() self.local_z()
} }
/// Translates the entity in the local space using a velocity and delta time. /// Moves the entity within its local space using the provided translation vector.
/// ///
/// The translation is applied directly to the entity's local position without considering /// This method directly adjusts the entity's position using the `translation` vector,
/// the entity's rotation. This means the entity moves along the provided velocity in its /// without considering the entity's current rotation. The translation happens in the
/// own local space. /// entity's local coordinate system, meaning the movement occurs along its local
/// axes (`x`, `y`, and `z`), regardless of the entity's orientation.
/// ///
/// # Parameters /// # Parameters
/// - `velocity`: A `Vec3` representing the multiplication of the direction and the /// - `translation`: A `Vec3` that represents the desired movement along the entity's
/// speed of the entity. /// local axes. Each component (`x`, `y`, `z`) corresponds to movement along the
/// - `delta_time_seconds`: A `f32` representing the time elapsed in seconds, typically /// entity's local right, up, and forward directions, respectively.
/// the time since the last frame. pub fn translate(&mut self, translation: Vec3) {
pub fn translate(&mut self, velocity: Vec3, delta_time_seconds: f32) { self.translation += translation;
self.translation += velocity * delta_time_seconds;
} }
/// Translates the entity in local space, taking into account the entity's rotation, speed, /// Moves the entity within its local space, considering its rotation and orientation.
/// and delta time.
/// ///
/// The translation is relative to the entity's rotation. This means the movement will be in /// This method translates the entity based on its current rotation, so the movement
/// the direction the entity is currently facing, which allows the entity to move "forward" /// happens relative to the direction the entity is facing. The `translation` vector is
/// or in any rotated direction relative to its local orientation. /// transformed by the entity's rotation, allowing for natural directional movement.
/// For instance, moving "forward" means moving along the entity's forward direction
/// based on its current orientation, rather than just along the local z-axis.
/// ///
/// # Parameters /// # Parameters
/// - `velocity`: A `Vec3` representing the multiplication of the direction and the speed /// - `translation`: A `Vec3` that represents the movement relative to the entity's local
/// of the entity, relative to the entity's local orientation. /// axes, but modified by the entity's current rotation. This means the movement will
/// - `delta_time_seconds`: A `f32` representing the time elapsed in seconds, typically /// be aligned with the entity's orientation in the world space.
/// the time since the last frame. pub fn translate_with_local_rotation(&mut self, translation: Vec3) {
pub fn translate_with_local_rotation(&mut self, velocity: Vec3, delta_time_seconds: f32) { self.translation += self.rotation * translation;
self.translation += self.rotation * velocity * delta_time_seconds;
} }
/// Rotates this [`Transform`] by the given rotation. /// Rotates this [`Transform`] by the given rotation.

View file

@ -68,6 +68,6 @@ fn move_cube(mut cubes: Query<(&mut Transform, &mut Movable)>, timer: Res<Time>)
if (cube.spawn - transform.translation).length() > cube.max_distance { if (cube.spawn - transform.translation).length() > cube.max_distance {
cube.speed *= -1.0; cube.speed *= -1.0;
} }
transform.translate(Vec3::X * cube.speed, timer.delta_seconds()); transform.translate(Vec3::X * cube.speed * timer.delta_seconds());
} }
} }