bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.25k stars 261 forks source link

How should sensors be implemented? #280

Closed PinkFatMan closed 11 months ago

PinkFatMan commented 11 months ago

In the game I am playing, I need to implement a mechanism sensor or trigger. How should I implement it better?

RossNordby commented 11 months ago

If you don't need contact-level precision and bounding boxes would suffice. broad phase queries would likely be easiest: Simulation.BroadPhase.GetOverlaps, for example.

If you need contact level precision on an object that should not actually collide with anything (no contact constraints), you could stick some bodies (or statics, if appropriate; note that statics cannot generate contacts with other statics) into the simulation and monitor the contacts they find during the narrow phase. Examples of this the CollisionTrackingDemo and ContactEventsDemo. You'd want to return false from INarrowPhaseCallbacks.ConfigureContactManifold to avoid creating collision constraints for sensor/trigger pairs.

If you want contact level precision on an object and you want collision response, you could also use something like the SolverContactEnumerationDemo. The other options still work too, but the SolverContactEnumerationDemo shows how to scan the actual contact constraints in the solver rather than reading things from the narrow phase callbacks.