Add AngularVelocity, begin removal of Rotation
The rotation component is also redundant with Bevy's transform component. This new component and system fill the physics role, but the input handling code needs to be updated. Player steering still functions because it uses the `Rotation` component to direct the force vector. The force is correctly applied to the linear velocity vector. An improvement would be to have a force/impulse accumulator so I could account for mass, but I'm not going to do that right now.
This commit is contained in:
@@ -61,7 +61,10 @@ impl Plugin for AsteroidPlugin {
|
|||||||
)
|
)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
FixedPostUpdate,
|
FixedPostUpdate,
|
||||||
(physics::integrate_velocity, physics::apply_rotation_to_mesh)
|
(
|
||||||
|
physics::integrate_velocity,
|
||||||
|
physics::integrate_angular_velocity,
|
||||||
|
)
|
||||||
.run_if(in_state(GameState::Playing)),
|
.run_if(in_state(GameState::Playing)),
|
||||||
)
|
)
|
||||||
.add_event::<asteroids::SpawnAsteroid>()
|
.add_event::<asteroids::SpawnAsteroid>()
|
||||||
|
|||||||
@@ -26,12 +26,15 @@ pub(crate) fn integrate_velocity(mut query: Query<(&mut Transform, &Velocity)>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/// Integrate angular velocity and update the entity's transform.
|
||||||
Assigns the rotation to the transform by copying it from the Rotation component.
|
pub(crate) fn integrate_angular_velocity(
|
||||||
*/
|
mut objects: Query<(&mut Transform, &AngularVelocity)>,
|
||||||
pub(crate) fn apply_rotation_to_mesh(mut query: Query<(&mut Transform, &Rotation)>) {
|
time: Res<Time>,
|
||||||
for (mut transform, rotation) in &mut query {
|
) {
|
||||||
transform.rotation = Quat::from_rotation_z(rotation.0);
|
for (mut transform, ang_vel) in &mut objects {
|
||||||
|
let delta = ang_vel.0 * time.delta_secs();
|
||||||
|
let temp = transform.rotation + Quat::from_rotation_z(delta);
|
||||||
|
transform.rotation = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user