Jump to content

Get rid of small bounce-back effect on collision with P2 physics


Recommended Posts

When implementing collision with P2, I can't seem to get rid of a small bounce-back effect.
In this example, when Mario jumps on the ground, it gets a little bit below the ground and then smoothly moves up quickly to stand on it. This doesn't happen with the Arcade physics and I can't seem to get rid of it with P2. Also every other example I've looked at has this effect and I tried several parameters.
Since I only need AABB collisions, another approach I tried is implementing the collision myself in the update() routine.
A very simple example for just a general ground would be:
if (player.body.y >= 500) {    player.body.y = 500;    player.body.velocity.y = 0;}

In this case, for one frame, the player appears below the ground. I assume this is, because this calculation would need to be done between the P2 physics calculations and the rendering, but the update() happens before the P2 physics calculations.

Does anyone know how to around this bounce-back effect I'm describing?
Link to comment
Share on other sites


Check this example, you can see that the keyboard bounces.

Now set the contactMaterial.restitution from 1.0 to 0.

No more bouncing.

Other example:


world.addContactMaterial(new p2.ContactMaterial(platformShape2.material, circleShape.material, {                restitution : 0.0, // This means no bounce!            }));
Link to comment
Share on other sites

this has nothing to do with the restitution..  as you can see in the example you postet the circle in the middle also "bounces" -- or in other words .. it sinks into the ground and then moves up again..  you need to observe very carefully to see it.. the faster the object is on collision the bigger the "sink/bounce" effect..


this is a p2 problem. i haven't seen this behaviour in box2d and i already tried to find out more about this but the only person that responded didn't want to see the difference ;-) 


try this box2d demo..  the box never sinks into the ground.. nomatter how hard you throw it 


Link to comment
Share on other sites

yeah but why are we talking about examples where restitution is key..  the topic starter clearly is NOT talking about the bounce effect caused by restitution.. he also postet an example where restitution is left to the default 0 (Zero) and precisely describes what he means.


the correct answer to this question is probably:


have a look at the relaxation parameter of p2 materials:


see this example and play with the values...  

the very high relaxation value makes the "bounce-back" go away.  but now it's stuck inside the other object (because it's not slowly bouncing back anymore)



Link to comment
Share on other sites

Thanks for the answers. I'll have a look at Box2D. :)


Sorry for the confusion, I should probably have used the work "sink" or something instead of "bounce".


It's really suprising to me that this phenomenon isn't a deal-breaker for more people. I mean, come on, that Mario example looks really weird with Mario sinking below the ground every time.

Link to comment
Share on other sites

i don't think it's that big of a problem.. it only happens if you fall down from a big height and only if the gravity is that high.. (most users use a lower setting than 1400)  AND you still can tweak the behaviour through stiffness, relaxation, restitution


in the real game you constantly walk and jump and look at enemies and the world surrounding you - so it isn't that obvious that the player sinks into an object.


BUT i would definitely want to hear what @rich and @schteppe have to say to this :)

Link to comment
Share on other sites


  • Recently Browsing   0 members

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