Stange value in OnCollisionEnter2D

I’ve been trying to understand this strange value for too long.

So I have a box and a platform. Both are box colliders with dynamic rigidbodies; The box has a gravity scale of 1, the platforms scale is 0. Both have a mass of 1.

I let the box fall on top and push the platform down. I have the box rotated so there is only one contact point. The platform Starts at a Y position of 0, the box is above it with a Y position of 2.

In OnCollisionEnter2D() I get these values.

Normal Impulse == 2.0601
Box Y Velocity == -2.0601
Platform Y Velocity == -2.0601
Platform Y Position == -0.05246176

How is the position of the platform calculated here?

If it’s velocity is -2.0601 then multiplying by fixedDeltaTime gives a position -0.041202. Can anyone help me understand this movement?

Unity uses Box2D for physics so you can see all the source code here for more detail.

The contact not hitting directly above the center of mass, contact offset, discrete collision detection allows slight overlaps which affect position (unlike continuous collision-detection) etc. All sorts of things change the collision response.

Given the set-up above assuming a contact island with a single contact, the specific source code that deals with it can be found in b2Island::Solve. Your platform/box is a single contact island with two bodies and no joints. Here is where it’s all handled; you’ll find the velocity, gravity and damping integration, the contact and joint solvers, position integration (the bit you’re interested in) and sleeping. If you’re using continuous then look at the following method b2Island::SolveTOI.

1 Like

Thank you for such a detailed response. Over the past couple years, I’ve read a bunch of your responses to others on the forums which have also helped me a bunch. I really appreciate it.

1 Like