schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

Sometimes the ball goes through the collision. #264

Open lcsweet opened 7 years ago

lcsweet commented 7 years ago

In the process of moving the ball sometimes through the collision body, the situation is the occasional occurrence.

schteppe commented 7 years ago

Hello, I think you need CCD but I'm not sure. A smaller time step can also help. Can you tell me more about your physics setup? Is it Circle vs Box or something else?

lcsweet commented 7 years ago

The moving ball has circle and polygon, is set up:

    body.angularDamping = 0;
    body.angularForce = 0;
    body.applyDamping(0);
    body.damping = 0;

Wall is BOX Address of the game:http://xchange-cq.com/test/ http://xchange-cq.com/demo/error1.png http://xchange-cq.com/demo/error1.png

schteppe commented 7 years ago

I see :) Try using a thicker box, or Plane shapes for the walls instead. If a shape is too thin it will allow for pass-through if the ball has high velocity.

jtenner commented 7 years ago

CCD is a lifesaver too.

Depends on if the object needs a high velocity.

issy123 commented 7 years ago

@jtenner how did you fix it with CCD, mind give me some code?

jtenner commented 7 years ago

check here

This has the code for adding continuous collision detection. It's very useful for fast moving objects that require precision.