Goshawk Posted July 14, 2018 Share Posted July 14, 2018 I have two sprites `bunny` and `baddy`. I want gravity to enact on `bunny` but not `baddy`. I understand that I can set `baddy.body.allowGravity()` to false but when I do this, gravity stops enacting on `bunny` too. I have discovered that it happens no matter whether I pass `true` or `false` to `allowGravity()` -- the result is always that gravity stops enacting on both sprites. function create() { // create the player sprite bunny = this.physics.add.sprite(200, 200, 'bunny'); bunny.body.setBounce(0.2); // our player will bounce from items bunny.body.setCollideWorldBounds(true); // don't go out of the map // create the baddy sprite baddy = this.physics.add.sprite(500,200, 'baddy'); baddy.body.allowGravity(true); // This isn't working as I expect it to!! cursors = this.input.keyboard.createCursorKeys(); } Am I doing anything obviously wrong? How do I prevent gravity enacting on `baddy` but not `bunny`? Link to comment Share on other sites More sharing options...
samme Posted July 14, 2018 Share Posted July 14, 2018 Check browser console. You need either body.setAllowGravity(false) body.allowGravity = false Goshawk 1 Link to comment Share on other sites More sharing options...
Recommended Posts