3
votes

I am creating a new physics group in Phaser 3, to hold platforms for my game.

this.testGroup = this.physics.add.group({ runChildUpdate: true })

I am adding a platform sprite to this group:

this.testGroup.add(new Platform(this, 400, 400, "platform"), true) 

And, in the sprite I am trying everything I can to set the gravity to 0

export class Platform extends Phaser.Physics.Arcade.Sprite {

constructor(scene) {
    super(scene, 100, 100, "texture")
    this.scene.physics.add.existing(this)

    this.body.setAllowGravity(false)
    this.setGravity(0)
    this.setImmovable(true)
    this.setVelocityY(0)
  }
}

But none of these options has any effect, the platform still falls straight down when running the game.

Why can't I set the gravity to 0 if I add an object to a physics group?

1
try this.body.allowGravity = false instead of this.body.setAllowGravity(false) - nazimboudeffa

1 Answers

4
votes

You have to disable gravity on the group too.

this.testGroup = this.physics.add.group({
        immovable: true,
        allowGravity: false
    });