Jump to content

Passing through walls instead of bouncing off when going fast using p2 physics


gillisig
 Share

Recommended Posts

Hi guys,

 

I am having some trouble using p2 physics and collision groups. I have walls and a ball that can be flung around with the mouse and bounces off the walls. However when the ball is going fast it simply passes through the walls instead of bouncing off them. 

 

Any idea what the problem may be? 

 

 

Link to comment
Share on other sites

jep...   tunneling is something completely normal when working without continuous collision detection..   

http://www.stencyl.com/help/view/continuous-collision-detection/

 

 

to avoid it use a function to limit the maximum speed of your moving objects or use thicker walls, or bigger moving objects OR  use walls made out of objects instead of polylines... it works much better (i already filed a github issue concerning objects VS poligons 

Link to comment
Share on other sites

and here one approach to limit the maximum speed :)   (run this on every frame)

function constrainVelocity(sprite, maxVelocity) {    if (!sprite || !sprite.body) {return;}    var body = sprite.body    var angle, currVelocitySqr, vx, vy;    vx = body.data.velocity[0];    vy = body.data.velocity[1];    currVelocitySqr = vx * vx + vy * vy;    if (currVelocitySqr > maxVelocity * maxVelocity) {        angle = Math.atan2(vy, vx);        vx = Math.cos(angle) * maxVelocity;        vy = Math.sin(angle) * maxVelocity;        body.data.velocity[0] = vx;        body.data.velocity[1] = vy;    }};
Link to comment
Share on other sites

Schteppe, the creator of p2, had the idea to integrate CCD very early and is aware of the issue. Unfortunately CCD is still missing. Maybe you should raise your voice in the original issue opened by schteppe himself. https://github.com/schteppe/p2.js/issues/28

 

Box2D is another physics engine which has CCD builtin. It's is not available in Phaser yet. It will be available as a Premium Plugin. See this announcement. http://www.photonstorm.com/phaser/phaser-v2-1-3-and-pixi-v2-are-out

 

If you're open for adventures you could try to integrate Box2D yourself in Phaser. I successfully tried it before and finished it within some hours for a limited scope. It is based on the box2d-html5(https://code.google.com/p/box2d-html5/) port of Box2D.

 

https://georgiee.github.io/phaser+box2d/

(source: https://github.com/georgiee/georgiee.github.io)

 

Regards George

Link to comment
Share on other sites

wow..  box2d integration..   it looks like box2d does one thing better than p2 :  every body that falls on the floor stops exactly above the floor while with p2 physics the bodies always go into the other bodies (the floor) and then move out of them quickly..  

 

I don't think that's the case in his demo, looks to me as if the behaviour is pretty much identical.

Link to comment
Share on other sites

in HIS demo this isn't the case..  like i said.. the bodies stop before entering the floor.. this looks very good...  with p2 it's different..  try this demo: https://schteppe.github.io/p2.js/demos/collisions.html   the objects sink in to the floor first if you let them go in great height.. it feels like the floor is made out of something soft..

Link to comment
Share on other sites

i cant do this in the example - can i ?

 

if this is the way to make it look like it doesn't sink into the ground i can not use it for obvious reasons..  but never mind..  it actually isnt a problem..   i just was surprised because it looks like (at leas to  me) that georges demo doesn't do this and i thought it's unavoidable :)

Link to comment
Share on other sites

oh you mean relaxation.. this doesn't change the amount of overlap it just speeds up the correction..  with very hight relaxation you can see the overlap in slomo :)

 

i guess i need to play around with the box2d example a little bit more to make out the differences ....

 

do you know if there is any difference between p2 and box2d performancewise?  

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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