mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-10 01:28:41 -06:00
normalize
This commit is contained in:
parent
889c193a05
commit
71154b07bc
|
@ -41,12 +41,12 @@ fn update_movement(
|
||||||
inputs: UniqueView<Inputs>,
|
inputs: UniqueView<Inputs>,
|
||||||
dt: UniqueView<DeltaTime>,
|
dt: UniqueView<DeltaTime>,
|
||||||
) {
|
) {
|
||||||
let movement = inputs.movement * 30. * dt.0.as_secs_f32();
|
if inputs.movement == Vec2::ZERO { return }
|
||||||
if 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() {
|
for (_, mut transform) in (&controllers, &mut transforms).iter() {
|
||||||
let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
|
let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
|
||||||
translation += (rotation * Vec3::NEG_Z) * movement.y;
|
translation += (rotation * Vec3::NEG_Z).normalize() * movement.y;
|
||||||
translation += (rotation * Vec3::X) * movement.x;
|
translation += (rotation * Vec3::X).normalize() * movement.x;
|
||||||
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
|
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation, translation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub fn update_raycasts(
|
||||||
}
|
}
|
||||||
for (transform, report) in (&transform, &mut raycast).iter() {
|
for (transform, report) in (&transform, &mut raycast).iter() {
|
||||||
let (_, rotation, position) = transform.0.to_scale_rotation_translation();
|
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.)));
|
*report = LookingAtBlock(world.raycast(position, direction, Some(30.)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue