Fractal Games Posted April 15, 2016 Share Posted April 15, 2016 Hi everyone, I am moving forward on my worms project. I have had a problem with P2 physics for a while that I cannot solve and I need to solve it for impact events. THE DEMO: (Chrome Firefox only) THE REPO: THE PROBLEM: On contact with my level (on a hill) my worm keeps sliding veeeery slowly and annoyingly. If the worm is in contact with the level he should stay still (but he won't). ATTEMPTED: Setting the body of the worm properties: velocity.x =0, velocity.y=0, rotation = 0, angle=0, angularDamping =0, angularVelocity = 0, gravityScale = 0.1 (allowGravityScale = true); Setting the game.physics.p2 properties: friction = 1 (tried 0, 1000, 3000 etc), p2.world.defaultContactMaterial.friction = same thing, restitution = 1; CODE OF INTEREST: WORM CLASS - specifically lines 112-117 GAME STATE Thanks in advance for your help! Link to comment Share on other sites More sharing options...
Fractal Games Posted April 17, 2016 Author Share Posted April 17, 2016 bump. Please help Link to comment Share on other sites More sharing options...
drhayes Posted April 18, 2016 Share Posted April 18, 2016 Caveat: I have zero (0, none, nada) experience with P2 physics. Don't you need to make ContactMaterials for those things? I'm pretty sure P2 doesn't know how to treat collisions between your ground and your Worm without them. (ref https://github.com/schteppe/p2.js/wiki#materials and http://paulsalaets.com/posts/friction-and-bounce-in-p2) I would love for there to be a multiplayer Worms game that's web-accessible, so please succeed. Link to comment Share on other sites More sharing options...
rgk Posted April 18, 2016 Share Posted April 18, 2016 Yeah your going to want to create a ContactMaterial with friction 1. This should cause the worm to stick to the ground. 10 hours ago, drhayes said: I would love for there to be a multiplayer Worms game that's web-accessible, so please succeed. Btw drhayes, AerialDrop is basically done! Now I need to really up the art. Link to comment Share on other sites More sharing options...
Fractal Games Posted April 18, 2016 Author Share Posted April 18, 2016 2 hours ago, rgk said: Yeah your going to want to create a ContactMaterial with friction 1. This should cause the worm to stick to the ground. Just made a commit with the contact material. It is not working for me. You can take a look in the demo. Your game looks cool. Would love to play it when it is ready 12 hours ago, drhayes said: I would love for there to be a multiplayer Worms game that's web-accessible, so please succeed. This will be unfortunately just a demo project. Making an html5 copy of worms would take me at least a couple of years. The worms' developers really knew their programming back in 1999 Link to comment Share on other sites More sharing options...
rgk Posted April 18, 2016 Share Posted April 18, 2016 Ok so I think this.wormBody.body.angularDamping = 0; might be causing your issue. You can try setting setZeroVelocity() or possibly set the worm to static even though I know thats not ideal. Also thank you! Link to comment Share on other sites More sharing options...
Fractal Games Posted April 19, 2016 Author Share Posted April 19, 2016 16 hours ago, rgk said: Ok so I think this.wormBody.body.angularDamping = 0; might be causing your issue. You can try setting setZeroVelocity() or possibly set the worm to static even though I know thats not ideal. Also thank you! Tried removing the angularDamping, also setZeroVelocity is not working. Even in the update when I set zero velocity (either with the method or by hand), the worm keeps moving and is affected by some sort of gravity. I would like to avoid static but if this is my only option, then I will have to... i guess... Link to comment Share on other sites More sharing options...
Fractal Games Posted April 20, 2016 Author Share Posted April 20, 2016 I managed to make it work with static, but it really is not an ideal solution. If anyone has and idea and the time to check for another solution, I would be thankful. Link to comment Share on other sites More sharing options...
Recommended Posts