ForgeableSum Posted May 30, 2015 Share Posted May 30, 2015 None of this seems to work: guy = game.add.sprite(100, 100, 'sprite');game.physics.startSystem(1);game.physics.p2.enable(guy, true);guy.body.allowGravity = false;guy.body.gravity.x = 0;guy.body.gravity.y = 0;guy.body.gravity = 0; "guy," the sprite, always acts as if there is gravity and falls to the bottom of the game world. Am I missing something here? Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 30, 2015 Author Share Posted May 30, 2015 This really doesn't make any sense I've read through the docs 10x, set every property imaginable and yet still the sprite flys around when added to the game world: game.physics.startSystem(Phaser.Physics.P2JS);game.physics.p2.applyGravity = false; game.physics.p2.applySpringForces = false; game.physics.p2.gravity = 0; guy = game.add.sprite(100, 100, 'sprite');game.physics.p2.enable(guy, true);game.physics.p2.enableBody(guy); guy.body.allowGravity = false;guy.body.gravity.x = 0;guy.body.gravity.y = 0; Link to comment Share on other sites More sharing options...
clement_cvL Posted May 31, 2015 Share Posted May 31, 2015 You should be able to turn off the gravity on the world you create.world.gravity = [0, 0];or you can set the body to be static with .body.mass = 0,or by setting its velocity to 0 :.body.velocity[0] = 0;.body.velocity[1] = 0; Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 31, 2015 Author Share Posted May 31, 2015 You should be able to turn off the gravity on the world you create.world.gravity = [0, 0];or you can set the body to be static with .body.mass = 0,or by setting its velocity to 0 :.body.velocity[0] = 0;.body.velocity[1] = 0;I've tried all 3 of these. No luck The sprite falls downward the moment I enable p2 physics on it. Setting the mass to 0 will cause it not to appear. sbonavida 1 Link to comment Share on other sites More sharing options...
george Posted May 31, 2015 Share Posted May 31, 2015 Hi,you nearly got it You mixed some arcade methods and you aren't aware of the p2 property gravityScale.//turn off globallygame.physics.p2.gravity.y = 0;//or thisgame.physics.p2.applyGravity = false//turn off locally (say: ignore gravity)//this property is not exposed by phaser so access //the original body from p2 with body.datasprite1.body.data.gravityScale = 0;See the appropriate phaser example:http://phaser.io/examples/v2/p2-physics/gravity-scale Whenever I'm searching for a property and I'm not able to find it in the documentation I switch over to 'source mode' to look for relevant methods. These are the relevant ones from P2 and Phaser:https://github.com/photonstorm/phaser/blob/63c9d2e88082cef5b702260d463647e1e348f4e3/src/physics/p2/World.js#L1903https://github.com/schteppe/p2.js/blob/5e9bdcd72ccf507db7d0fa5d1f9f3364d0f02c86/src/objects/Body.js#L393https://github.com/schteppe/p2.js/blob/5e9bdcd72ccf507db7d0fa5d1f9f3364d0f02c86/src/world/World.js#L124 ForgeableSum and tidelake 2 Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 31, 2015 Author Share Posted May 31, 2015 Hi,you nearly got it You mixed some arcade methods and you aren't aware of the p2 property gravityScale.//turn off globallygame.physics.p2.gravity.y = 0;//or thisgame.physics.p2.applyGravity = false//turn off locally (say: ignore gravity)//this property is not exposed by phaser so access //the original body from p2 with body.datasprite1.body.data.gravityScale = 0;See the appropriate phaser example:http://phaser.io/examples/v2/p2-physics/gravity-scale Whenever I'm searching for a property and I'm not able to find it in the documentation I switch over to 'source mode' to look for relevant methods. These are the relevant ones from P2 and Phaser:https://github.com/photonstorm/phaser/blob/63c9d2e88082cef5b702260d463647e1e348f4e3/src/physics/p2/World.js#L1903https://github.com/schteppe/p2.js/blob/5e9bdcd72ccf507db7d0fa5d1f9f3364d0f02c86/src/objects/Body.js#L393https://github.com/schteppe/p2.js/blob/5e9bdcd72ccf507db7d0fa5d1f9f3364d0f02c86/src/world/World.js#L124 Thanks, I guess I've gotten too used to arcade physics. I tried those properties and no luck. What's odd is that the first time I loaded the screen the sprite did not move with gravity turned off. Then when I turned gravity back on, reloaded, turned it off, reloaded, it no longer acted as if gravity was turned off. Or maybe that was all in my imagination and I'm just going mad. Here's a code pen: http://codepen.io/anon/pen/yNgqeV Link to comment Share on other sites More sharing options...
george Posted May 31, 2015 Share Posted May 31, 2015 You're object is placed outside of the world bounds so it gets pushed inside. Therefore your object has some amount of velocity but there is no gravity at all - the object is just floating around. Here two fixed versions to make this clear. Gravity working:http://codepen.io/anon/pen/WvRKxr and then gravity disabled on the object with gravity scale.http://codepen.io/anon/pen/jPyprr ForgeableSum 1 Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 31, 2015 Author Share Posted May 31, 2015 You're object is placed outside of the world bounds so it gets pushed inside. Therefore your object has some amount of velocity but there is no gravity at all - the object is just floating around. Here two fixed versions to make this clear. Gravity working:http://codepen.io/anon/pen/WvRKxr and then gravity disabled on the object with gravity scale.http://codepen.io/anon/pen/jPyprrWow, the velocity set because of the world bounds really threw me off. It all makes sense now, thanks! Link to comment Share on other sites More sharing options...
Recommended Posts