Skip to content

Commit ee81252

Browse files
committed
[update] steps to clear accumulated forces after each step.
1 parent a15de50 commit ee81252

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

crates/lambda-rs/src/physics/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

crates/lambda-rs/src/physics/rigid_body_2d.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)