From 939ffc70a199a560ed5bcf1ebe7c637af24866c3 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sat, 9 Aug 2025 15:50:54 -0500 Subject: [PATCH] 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. --- src/lib.rs | 5 ++++- src/physics.rs | 15 +++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 60c547e..4415e96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,10 @@ impl Plugin for AsteroidPlugin { ) .add_systems( FixedPostUpdate, - (physics::integrate_velocity, physics::apply_rotation_to_mesh) + ( + physics::integrate_velocity, + physics::integrate_angular_velocity, + ) .run_if(in_state(GameState::Playing)), ) .add_event::() diff --git a/src/physics.rs b/src/physics.rs index 503ce87..d41fd75 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -26,12 +26,15 @@ pub(crate) fn integrate_velocity(mut query: Query<(&mut Transform, &Velocity)>, } } -/* - Assigns the rotation to the transform by copying it from the Rotation component. -*/ -pub(crate) fn apply_rotation_to_mesh(mut query: Query<(&mut Transform, &Rotation)>) { - for (mut transform, rotation) in &mut query { - transform.rotation = Quat::from_rotation_z(rotation.0); +/// Integrate angular velocity and update the entity's transform. +pub(crate) fn integrate_angular_velocity( + mut objects: Query<(&mut Transform, &AngularVelocity)>, + time: Res