alex_h Posted June 15, 2016 Share Posted June 15, 2016 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! Quote Link to comment Share on other sites More sharing options...
symof Posted June 15, 2016 Share Posted June 15, 2016 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. Quote Link to comment Share on other sites More sharing options...
Milton Posted June 15, 2016 Share Posted June 15, 2016 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 }); symof 1 Quote Link to comment Share on other sites More sharing options...
symof Posted June 16, 2016 Share Posted June 16, 2016 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. DevJ 1 Quote Link to comment Share on other sites More sharing options...
alex_h Posted June 16, 2016 Author Share Posted June 16, 2016 Thanks for the replies. I'll try modifying the friction and see what happens. I might also consider increasing the mass, probably not quite as high as was suggested though Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.