File tree Expand file tree Collapse file tree
crates/lambda-rs/src/physics Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,8 @@ impl PhysicsWorld2D {
5353 . step_with_timestep_seconds ( substep_timestep_seconds) ;
5454 }
5555
56+ self . backend . clear_rigid_body_forces_2d ( ) ;
57+
5658 return ;
5759 }
5860
Original file line number Diff line number Diff line change @@ -723,4 +723,35 @@ mod tests {
723723
724724 return ;
725725 }
726+
727+ #[ test]
728+ fn step_clears_accumulated_forces_once_per_outer_step ( ) {
729+ let mut world = PhysicsWorld2DBuilder :: new ( )
730+ . with_gravity ( 0.0 , 0.0 )
731+ . with_timestep_seconds ( 1.0 )
732+ . with_substeps ( 2 )
733+ . build ( )
734+ . unwrap ( ) ;
735+
736+ let body = RigidBody2DBuilder :: new ( RigidBodyType :: Dynamic )
737+ . build ( & mut world)
738+ . unwrap ( ) ;
739+
740+ world
741+ . backend
742+ . rigid_body_apply_force_2d (
743+ body. slot_index ,
744+ body. slot_generation ,
745+ [ 1.0 , 0.0 ] ,
746+ )
747+ . unwrap ( ) ;
748+
749+ world. step ( ) ;
750+ assert_eq ! ( body. position( & world) . unwrap( ) , [ 0.75 , 0.0 ] ) ;
751+
752+ world. step ( ) ;
753+ assert_eq ! ( body. position( & world) . unwrap( ) , [ 1.75 , 0.0 ] ) ;
754+
755+ return ;
756+ }
726757}
You can’t perform that action at this time.
0 commit comments