Jump to content

How to achieve 100% bounce energy return with P2?


rosancoderian
 Share

Recommended Posts

set restitution to 1  - that should do it..   of course in this example there is no gravity and no damping involved so gravity should be 0 and damping should also be 0 

 game.physics.p2.restitution=1;

this sets the restitution for the whole world..  better would be to use materials

can you give me some example please?

 

Edit:

oh sorry i forgot to call setZeroDamping()

it solved now, thanks  :lol:

Link to comment
Share on other sites

great!   materials in short: 

groundMaterial = game.physics.p2.createMaterial();  //create materialplayerMaterial = game.physics.p2.createMaterial();game.physics.p2.createContactMaterial(playerMaterial, groundMaterial, { friction: 2,  restitution: 1  });   //define what happens when 2 materials meetplayer.body.setMaterial(playerMaterial);  //assign materials to objectsforeground.body.setMaterial(groundMaterial);
Link to comment
Share on other sites

Restitution=1 should do it, though you might need to set a larger stiffness value too.

See this "raw" p2 demo: http://schteppe.github.io/p2.js/demos/restitution.html

Even though you get it right, expect some round off errors. You should make sure that your velocity vector always has a constant length. Don't have code for this yet, but could write something up if you need it!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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