JakeCake Posted July 3, 2014 Share Posted July 3, 2014 So my current project builds around gravity quite a lot, and the "gravityScale" simply doesn't cut it anymore, I need to apply gravity to different objects with entirely different gravity vectors. At the moment I am using: game.physics.p2.gravity.x = calculatedGravity.x;game.physics.p2.gravity.y = calculatedGravity.y; but this applies to ALL objects. Bodies in P2 doesn't seem to have the local gravity settings that Arcade physics gives, but then again, I might just be using it wrong. Before I altogether disable the P2 gravity system (game.physics.p2.applyGravity = false) and create my own by adding to all object's force each step, I would like to hear if anyone else had this problem and fixed it or have any idea how to. Thank you for any help PS: I couldn't find anything about this in the P2 documentation, so it is most likely a limitation in P2, not Phaser. Link to comment Share on other sites More sharing options...
wayfinder Posted July 3, 2014 Share Posted July 3, 2014 It *is* a limitation in Phaser, as far as I know. Here's the relevant bit from the Phaser docs: gravity Phaser.PointA locally applied gravity force to the Body. Applied directly before the world step. NOTE: Not currently implemented. edit: Looks like you're stuck with using applyForce to simulate gravity. Careful: The docs on applyForce specify the force as a Number, but it really expects a p2 vector (a Float32Array with [0] being x and [1] being y, in p2 units per second - use Phaser.Physics.P2.pxmi(value) to convert pixels to p2 units) Link to comment Share on other sites More sharing options...
JakeCake Posted July 4, 2014 Author Share Posted July 4, 2014 Thank you for the answer. I am going to implement it myself for now then. Link to comment Share on other sites More sharing options...
Recommended Posts