MXPain Posted August 11, 2014 Share Posted August 11, 2014 Please tell me how I can get impulse value from contact between two bodies? Link to comment Share on other sites More sharing options...
wayfinder Posted August 12, 2014 Share Posted August 12, 2014 What do you mean by impulse value? Link to comment Share on other sites More sharing options...
schteppe Posted August 13, 2014 Share Posted August 13, 2014 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.htmlFyi, the multiplier is proportional to the force.Should make a demo for this... Link to comment Share on other sites More sharing options...
MXPain Posted August 13, 2014 Author Share Posted August 13, 2014 thank you very much, I'll try Link to comment Share on other sites More sharing options...
MXPain Posted August 13, 2014 Author Share Posted August 13, 2014 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 impactcollisionHandlerHero: function (body, shapeA, shapeB, equation) { if(equation[0]!=null) console.log(equation[0].multiplier);} Link to comment Share on other sites More sharing options...
schteppe Posted August 13, 2014 Share Posted August 13, 2014 Nice. So, what more do you need? Link to comment Share on other sites More sharing options...
lewster32 Posted August 13, 2014 Share Posted August 13, 2014 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 More sharing options...
schteppe Posted August 13, 2014 Share Posted August 13, 2014 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. clark 1 Link to comment Share on other sites More sharing options...
MXPain Posted August 14, 2014 Author Share Posted August 14, 2014 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); }} lewster32 1 Link to comment Share on other sites More sharing options...
defic Posted December 8, 2014 Share Posted December 8, 2014 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. fariazz 1 Link to comment Share on other sites More sharing options...
Recommended Posts