MXPain

p2 Contact impulse

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...

Share this post


Link to post
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);}

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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);       }}

Share this post


Link to post
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);       }}

 

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.