@@ -110,6 +110,7 @@ impl Plugin for CharacterControllerPlugin {
110110                ) 
111111                    . run_if ( in_state ( InGameState :: Playing ) ) , 
112112            ) 
113+             . add_systems ( Update ,  apply_movement_damping) 
113114            . add_systems ( 
114115                OnEnter ( InGameState :: PlayerDead ) , 
115116                handle_player_dead_velocity, 
@@ -156,13 +157,6 @@ fn handle_keyboard_input_for_player(
156157        local_velocity. z  += 1.0  *  speed; 
157158    } 
158159
159-     let  world_velocity = player_transform. rotation  *  local_velocity; 
160- 
161-     movement_action_writer. write ( MovementAction  { 
162-         direction :  MovementDirection :: Move ( world_velocity) , 
163-         character_controller_entity :  player_entity, 
164-     } ) ; 
165- 
166160    if  local_velocity. x  == 0.0  && local_velocity. z  == 0.0  { 
167161        if  movement_state. 0  != MovementStateEnum :: Idle  { 
168162            movement_state. 0  = MovementStateEnum :: Idle ; 
@@ -177,6 +171,17 @@ fn handle_keyboard_input_for_player(
177171        } 
178172    } 
179173
174+     if  local_velocity == Vec3 :: ZERO  { 
175+         return ; 
176+     } 
177+ 
178+     let  world_velocity = player_transform. rotation  *  local_velocity; 
179+ 
180+     movement_action_writer. write ( MovementAction  { 
181+         direction :  MovementDirection :: Move ( world_velocity) , 
182+         character_controller_entity :  player_entity, 
183+     } ) ; 
184+ 
180185    if  keyboard_input. just_pressed ( KeyCode :: Space )  { 
181186        movement_action_writer. write ( MovementAction  { 
182187            direction :  MovementDirection :: Jump , 
@@ -223,10 +228,6 @@ fn handle_movement_actions_for_character_controllers(
223228                let  Ok ( direction_from_world_velocity)  =
224229                    Dir3 :: new ( world_velocity) 
225230                else  { 
226-                     // can also be happen when velocity is Vec3::ZERO but i kinda dont want that 
227-                     // because if velocity is zero there should be no message written. could save a 
228-                     // bit of perf i guess 
229-                     warn ! ( "Setting zero velocity" ) ; 
230231                    velocity. x  = 0.0 ; 
231232                    velocity. z  = 0.0 ; 
232233                    return ; 
@@ -344,3 +345,11 @@ fn apply_gravity_over_time(
344345        } 
345346    } 
346347} 
348+ 
349+ // Apply damping in the XZ Plane, basically this is deceleration over time 
350+ fn  apply_movement_damping ( query :  Query < & mut  LinearVelocity > )  { 
351+     for  mut  velocity in  query { 
352+         velocity. x  *= 0.9 ; 
353+         velocity. z  *= 0.9 ; 
354+     } 
355+ } 
0 commit comments