schteppe / p2.js

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

Continuous collision detection #149

Closed enriqueto closed 9 years ago

enriqueto commented 9 years ago

any plans for that?

schteppe commented 9 years ago

Probably in the future! Needs some work: capsule casting (maybe it can work with ordinary ray casting too) and binary searching for time of impact.

enriqueto commented 9 years ago

let me know if I can help, unfortunately I am not familiar with physics engines

schteppe commented 9 years ago

Well, if you decide to get familiar with p2, you could start porting the Cannon.js raycast methods and classes:

CANNON.World.prototype.raycastAll
CANNON.World.prototype.raycastAny
CANNON.World.prototype.raycastClosest
CANNON.RaycastResult
CANNON.Ray

I think that regular rays are a good start. If not, it's still a great feature :)

enriqueto commented 9 years ago

Alright. Although I'm quite busy I'll take a look to those classes

schteppe commented 9 years ago

@enriqueto The classes and World methods are in place along with an example.

To do now is

  1. using it for roughly detect collision. This is done just before integrating / updating position of bodies, if the body is moving fast.
  2. Estimate time of impact, using binary search and the justTest flag in the Narrowphase.
  3. Move the body to the time of impact.

Will continue working on this whenever I get some coding time over. I really want this feature for p2.js and cannon.js too :)

enriqueto commented 9 years ago

thanks, let see if I can understand that

schteppe commented 9 years ago

@enriqueto lol don't worry I got this :P

I got 1 and 3 in place now, and instead of 2 I just use the raycast hit point. Now I just need to implement binary searching for the time of impact to make it more accurate.

You should be able to use this feature now by building p2.js locally and setting ccdThreshold to 0 on the body. See the ccd demo. It won't be very accurate, but it will work better than nothing :)

schteppe commented 9 years ago

Added binary searching too! Should be working good now :)

enriqueto commented 9 years ago

Thanks, I felt a bit overwhelmed by that since I haven't got any experience programming game frameworks, just using them. Will try that next time I update FootChinko.