dimforge / dimforge/nphysics

Until `MechanicalWorld::step` is called, `GeometricalWorld::interferences_with_point` uses old collider positions

Open
#279 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.6k
Forks
120
PR merge metrics
No merged PRs in 30d

Description

For context, I am writing a level editor that uses `interferences_with_point` to determine the entities the user are clicking on. When the user moves an entity, the underlying body's position is moved. However, the call to `interferences_with_point` still seems to be using the old object's position until the next time `step` is called. I have tried both updating the collider position along with the body and using `GeometricalWorld::sync_colliders`, which has had no effect. Reading through the source of `step`, I have taken a few stabs in the dark on what will finally allow `interferences_with_point` to work (without actually calling `step`), culminating with this:

```rust
mech: DefaultMechanicalWorld,
geo: DefaultGeometricalWorld,
bodies: DefaultBodySet,
colliders: DefaultColliderSet,
joints: DefaultJointConstraintSet,
forces: DefaultForceGeneratorSet,
...
self.mech.maintain(&mut self.geo, &mut self.bodies, &mut self.colliders, &mut self.joints);
self.geo.clear_events();
self.geo.sync_colliders(&self.bodies, &mut self.colliders);
self.geo.perform_broad_phase(&self.colliders);
self.geo.perform_narrow_phase(&self.colliders);
self.colliders.foreach_mut(|_, c| c.clear_update_flags());
```

Still, this did not work. In the end, my workaround was this:

```rust
let old_timestep = self.mech.timestep();
self.mech.set_timestep(0.0);
self.mech.step(
&mut self.geo,
&mut self.bodies,
&mut self.colliders,
&mut self.joints,
&mut self.forces,
);
self.mech.set_timestep(old_timestep);
```
This feels like a bit of a hack, especially in the presence of all those other functions which I expected to work, having read the source, but I am all out of leads.

Is there a specific algorithm that users of nphysics are supposed to use to ensure `interferences_with_point` is querying an up to date world, or is this perhaps a bug in the library?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.