1
\$\begingroup\$

I have three dynamic Rigidbody2D's, two of them paddles and the other a ball - this ball is also a trigger. If I used OnCollisionEnter before, I understand that the physics engine calculates the collision that should happen based on the position and velocity of the ball and paddle. This created the so called lag problem I had where seemingly two collision results happened. However, now I am using OnTriggerEnter and have a couple questions related to the problem I'm having.

When the ball is level with the paddle on the x-axis and you move up to hit it, the paddle is able to go through the ball but the collision happens from where the ball hit the paddle originally. Why is this? Also, if I print the x position of the ball, the position should be 7.175 but instead it's 7.19996, is there a way to get the actual point of collision? Is this linked to the first question?

Thanks!

\$\endgroup\$
1
\$\begingroup\$

It sounds like you might be asking about continuous collision detection.

When this is enabled, the physics engine considers the full swept movement of the object over the duration of the physics time step. If there is a collision, we can pinpoint the precise moment of contact and respond accordingly.

The trouble is, this is a very expensive way to detect collisions. So the default behaviour for most game physics is a simpler method: move every object through its full displacement for the physics time step, then check if any are overlapped. If they are (and aren't triggers - triggers detect collisions but don't resolve them), try to nudge them so they're no longer overlapped.

If you need full continuous collision precision for a small number of objects in your scene, you can enable it in their Rigidbody2D's collision detection mode property. Or you can "scan ahead" of the object with raycasts/circle casts to find pending collisions and handle the bouncing yourself.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.