Collision event, normal direction

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
S0nix
Posts: 4
Joined: Sat Nov 24, 2018 12:30 pm

Collision event, normal direction

Post by S0nix » Wed Nov 28, 2018 9:13 am

Hi,

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?

Norbo
Site Admin
Posts: 4558
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision event, normal direction

Post by Norbo » Wed Nov 28, 2018 11:48 pm

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.

S0nix
Posts: 4
Joined: Sat Nov 24, 2018 12:30 pm

Re: Collision event, normal direction

Post by S0nix » Fri Nov 30, 2018 7:54 am

Thanks for the help. I now conditionally invert the normal.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest