schteppe / p2.js

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

Have any demos about to get two bodies contact points? #325

Closed guawoo closed 6 years ago

guawoo commented 6 years ago

I can not found a demo about to get contact points when bodies collided. I only found a topic about this was a phaser approach, but my project is not phaser :(.

Foxhunt commented 6 years ago

Check this part of the Demo code.

i use this function to detect collisions and spawn some particles at that point.

function findContacts(){
    for(let i = 0; i < world.narrowphase.contactEquations.length; i++){
        let eq = world.narrowphase.contactEquations[i]
        let bodyAPosition = eq.bodyA.position
        let contactPointA = eq.contactPointA

        let contactX = bodyAPosition[0] + contactPointA[0]
        let contactY = bodyAPosition[1] + contactPointA[1]

        spawnParticle(contactX, contactY)
    }
}
guawoo commented 6 years ago

oh, that great! thank you so mush. :)