Custom prediction of collision resolution

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
kakebuke
Posts: 5
Joined: Fri Mar 20, 2020 4:05 pm

Custom prediction of collision resolution

Post by kakebuke »

Hello,
I am trying to show the prediction of a collision between 2 spheres (I need to know the velocity of both spheres after the collision). The issue I am having is that with the tests that I did I only got something similar to an elastic collision, but that's not what Bepu does and not what I am looking for.

The solution I am trying looks like this:

I calculate the tangent based on the normal of the collision. Then some pseudo code:

dotTangent = Dot(tangent, velocitySphere1)
dotNormalOther = Dot(normal, velocitySphere2)

Velocity = tangent * dotTangent + normal * dotNormalOther

The velocities are not being normalized, so they look a bit like an inelastic collision, but the prediction does not match the result. And btw, I disabled drag and damping for the test.

Though It seems to me that one solution would be to run forward the state until the collision happens and get the velocities after that, without updating the view, and rollback the state of the world to its original positions. Is there a way to do that?

Another one could be to somehow try to call an isolated collision solving method that produces the output values we need, and call it with the correct input values and make the resolution solver call the same method, but diggin into the guts of BEPU is kind of scary at this point.

Does anyone have a better solution / calculation?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Custom prediction of collision resolution

Post by Norbo »

Unless there's a reason not to (like performance budget), I'd recommend just going with running the simulation forward. There's no built in 'rewind' functionality, but you could cache the original position/orientation/velocities and reset them afterwards. Or create a separate simulation, create equivalent objects in that simulation, and simulate it forward instead.

Note that there's no guarantee that the prediction will perfectly match what the simulation ends up doing in either case- there's a lot of internal state that will cause divergence if not perfectly replicated. Doing that replication would be a huge buttpain, so it's usually not worth it. It'll be a closer prediction than an out-of-engine approximation either way.
Post Reply