Jump to content

Anybody good with p2 physics?


alex_h
 Share

Recommended Posts

I'm building a game for young kids using p2 physics, there are building blocks on screen and you can drag them around to build stuff. The problem is that the blocks won't stay still so it's really hard to build even a stack of 3 or more. I've tried lots of things to stop them jiggling around so much but nothing has quite got them how I want them.

I've tried using a friction material, increasing the mass of building blocks, applying maximum (0.99) damping to the blocks and increasing the default stiffness value for equations p2.Equation.DEFAULT_STIFFNESS = 2e6; I have set the building blocks to sleep, I have even set it so that a lock constraint is used to fix blocks together if they connect at an appropriate angle. But its still not really working enough. Is there some simple thing I'm missing? Some property of bodies that I can adjust to make them stay still?

In the p2 physics world I've set gravity to -30, and blocks have the following properties:

//apply some angular damping
    body.angularDamping = 0.4;

    body.type = p2.Body.DYNAMIC;

    body.sleepSpeedLimit = 0.1; // Body will feel sleepy if speed<1 (speed is the norm of velocity)
    body.sleepTimeLimit =  1; // Body falls asleep after 1s of sleepiness

    body.mass = 10;
    body.damping = 0.99;//0.95;
    body.updateMassProperties();

Any suggestions or direction offered would be gratefully received!

Link to comment
Share on other sites

If you set the body.mass to a really high number(like 99999999999999999) they will stay still. I don't know how you place the boxes but if you add mass based on their current .y coordinate, and make it so that their mass is relative to their current "height" it should work.

Link to comment
Share on other sites

2 hours ago, Milton said:

I looked at something similar a while back (post). It seemed that the friction was actually causing the jiggling. So maybe you could try something like:


var boxBoxCM = game.physics.p2.createContactMaterial(boxMaterial, boxMaterial, { friction: 0 });

 

He is right.

As per this example:

http://phaser.io/examples/v2/p2-physics/platformer-material

if you change game.physics.p2.world.defaultContactMaterial.friction = 0.3; to 0 then you get no jiggling.

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...