Jump to content

Worms Game P2 physics Question (+ demo)


Fractal Games
 Share

Recommended Posts

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!

 

 

wormProblem.png

Link to comment
Share on other sites

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

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

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 :D 

Link to comment
Share on other sites

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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