gillisig Posted December 14, 2014 Share Posted December 14, 2014 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 More sharing options...
valueerror Posted December 15, 2014 Share Posted December 15, 2014 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 More sharing options...
valueerror Posted December 15, 2014 Share Posted December 15, 2014 https://github.com/schteppe/p2.js/issues/136 here the github issue with an example Link to comment Share on other sites More sharing options...
valueerror Posted December 15, 2014 Share Posted December 15, 2014 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 More sharing options...
george Posted December 15, 2014 Share Posted December 15, 2014 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 More sharing options...
valueerror Posted December 15, 2014 Share Posted December 15, 2014 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.. Link to comment Share on other sites More sharing options...
wayfinder Posted December 15, 2014 Share Posted December 15, 2014 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 More sharing options...
valueerror Posted December 15, 2014 Share Posted December 15, 2014 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 More sharing options...
wayfinder Posted December 15, 2014 Share Posted December 15, 2014 No what I meant was, that in his demo it also happens, The speeds aren't as high, and the restitution and separation is a little different, but the shapes still overlap slighty. Link to comment Share on other sites More sharing options...
valueerror Posted December 15, 2014 Share Posted December 15, 2014 oh sorry.. i got it the other way around.. but still.. i don't see the behaviour in the box2d demo but i can always see it in the p2 demo.. i changed the gravity to something very low and created circles in the same height above the ground as in the box2d demo.. almost all circles overlapped.. Link to comment Share on other sites More sharing options...
wayfinder Posted December 15, 2014 Share Posted December 15, 2014 Try setting p2 restitution to 1. Link to comment Share on other sites More sharing options...
valueerror Posted December 16, 2014 Share Posted December 16, 2014 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 More sharing options...
wayfinder Posted December 16, 2014 Share Posted December 16, 2014 Oh I'm sorry, it's relaxation I can't really speak with any authority about the actual features of Box2D Just saw that there was overlap in George's example (which isn't a criticism btw) Link to comment Share on other sites More sharing options...
valueerror Posted December 16, 2014 Share Posted December 16, 2014 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 More sharing options...
Recommended Posts