Jump to content

p2 Contact impulse


MXPain
 Share

Recommended Posts

I think you are looking for the .multiplier property of the involved ContactEquations.

You can get all contact equations in world.narrowphase.contactEquations, make sure to filter out the ones you need by checking equation.bodyA and .bodyB.

A related demo is the tearable demo: http://schteppe.github.io/p2.js/demos/tearable.html

Fyi, the multiplier is proportional to the force.

Should make a demo for this...

Link to comment
Share on other sites

schteppe, I wrote the following code to check, but the value of Multiplier for some reason does not fall below 24 and in contact of bodies varies very little. My goal with a strong impact on the character of the body play a sound impact

collisionHandlerHero: function (body, shapeA, shapeB, equation) {        if(equation[0]!=null) console.log(equation[0].multiplier);}
Link to comment
Share on other sites

Is there not a feature in P2 where you can get the velocity of the objects before the collision is processed? If so, you could use the magnitude of the velocity of the second object to determine the impact strength. I'm sorry if I'm way out here, as I've not used P2, but this would be my initial thinking.

Link to comment
Share on other sites

Getting the velocities would be possible, but unfortunately that's not a one-liner as it is right now... Would be a nice feature though!

 

To get such velocities as the lib is now, get the ContactEquations in the preSolve event. Then filter out the interesting ones. Then get the velocities of the bodies at the contact points.

Link to comment
Share on other sites

Thanks all, here is my resulting code, I decided to check the speed at the moment of impact:

    collisionHandlerHero: function (body, shapeA, shapeB, equation) {       if(equation[0]!=null)       {           var res = Phaser.Point.distance(new Phaser.Point(equation[0].bodyB.velocity[0],equation[0].bodyB.velocity[1]), new Phaser.Point(0,0));           console.log(res);       }}
Link to comment
Share on other sites

  • 3 months later...

 

Thanks all, here is my resulting code, I decided to check the speed at the moment of impact:

    collisionHandlerHero: function (body, shapeA, shapeB, equation) {       if(equation[0]!=null)       {           var res = Phaser.Point.distance(new Phaser.Point(equation[0].bodyB.velocity[0],equation[0].bodyB.velocity[1]), new Phaser.Point(0,0));           console.log(res);       }}

 

Thanks, this helped me a lot. Though I edited the code little bit to calculate the difference between the velocitys of the colliding bodies:

var res = Phaser.Point.distance(new Phaser.Point(equation[0].bodyB.velocity[0],equation[0].bodyB.velocity[1]), new Phaser.Point(equation[0].bodyA.velocity[0],equation[0].bodyA.velocity[1]));console.log(res);

So if we have 2 moving objects and they are f.e. free falling and slightly touching each other,the impact would not generate a sound.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...