rosancoderian

How to achieve 100% bounce energy return with P2?

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

Share this post


Link to post
Share on other sites

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:

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.