normalize

This commit is contained in:
griffi-gh 2023-01-29 23:19:24 +01:00
parent 889c193a05
commit 71154b07bc
2 changed files with 5 additions and 5 deletions

View file

@ -41,12 +41,12 @@ fn update_movement(
inputs: UniqueView<Inputs>,
dt: UniqueView<DeltaTime>,
) {
let movement = inputs.movement * 30. * dt.0.as_secs_f32();
if movement == Vec2::ZERO { return }
if inputs.movement == Vec2::ZERO { return }
let movement = inputs.movement.normalize_or_zero() * 30. * dt.0.as_secs_f32();
for (_, mut transform) in (&controllers, &mut transforms).iter() {
let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
translation += (rotation * Vec3::NEG_Z) * movement.y;
translation += (rotation * Vec3::X) * movement.x;
translation += (rotation * Vec3::NEG_Z).normalize() * movement.y;
translation += (rotation * Vec3::X).normalize() * movement.x;
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
}
}

View file

@ -59,7 +59,7 @@ pub fn update_raycasts(
}
for (transform, report) in (&transform, &mut raycast).iter() {
let (_, rotation, position) = transform.0.to_scale_rotation_translation();
let direction = rotation * Vec3::NEG_Z;
let direction = (rotation * Vec3::NEG_Z).normalize();
*report = LookingAtBlock(world.raycast(position, direction, Some(30.)));
}
}