Page 1 of 1

Collision event, normal direction

Posted: Wed Nov 28, 2018 9:13 am
by S0nix

I currently try to build an abstraction layer on top of the bepu collision events. For simplicity I only plan to expose the InitialCollisionDetected and CollisionEnded event.
When the InitialCollisionDetected event occurs I want to forward the colliding game entities (stored in the tag), the collision point and the collision normal. For this I just forward the data in the first contact in the CollidablePairHandler. This works well except for the collision normal.
My problem is that if 2 entities collide which both have subscribed to the InitialCollisionDetected event they both get notified but with the same collision normal. I would expect the normals to face in the opposite direction (away from the entity they collided with).
Is their a way to get a behavior like this or is my expectation for the normals just wrong?

Re: Collision event, normal direction

Posted: Wed Nov 28, 2018 11:48 pm
by Norbo
It's been long enough that I'm not 100% confident in this, but I believe all normals in v1 are calibrated to point from A to B in a pair. So if you have the body reference and the pair, you can conditionally negate the normal.

It's possible that I didn't hold to this consistently in every pair type- I don't think I ever documented that particular behavior. Worst case scenario, if the event-firing body is convex, you can manually calibrate it relative to the offset from the body position to the contact position (e.g. normal = Vector3.Dot(normal, bodyPosition - contactPosition) < 0 ? -normal : normal))

It's worth mentioning that v2 behaves a bit differently. In addition to not having events at all (in favor of a low level callback that events can optionally be built on top of), all normals are calibrated to point from B to A.

Re: Collision event, normal direction

Posted: Fri Nov 30, 2018 7:54 am
by S0nix
Thanks for the help. I now conditionally invert the normal.