Skip to content
Advertisement

How to handle collisions in Phaser

I want to make objects push away from each other in my Phaser game (arcade physics). To do so I’ve tried to use the collider function:

  let avatar = this.physics.add.sprite(
    localStorage.x ? localStorage.x*1 : 300,
    localStorage.y ? localStorage.y*1 : 300,
    "avatar",
    0
  );

let tree = this.physics.add.image(100, 0, "bigtree");
  tree.setScale(4, 4);
  tree.setImmovable();
  this.physics.add.collider(avatar, tree); 

But I always get TypeError: undefined is not an object (evaluating 't.isParent')

It looks like this is error rises during the update process as it’s risen thousand times a minute…

I’m using Phaser 3

Does anyone know the answer?

Thanks!

Advertisement

Answer

Turns out you have to put those collider functions in the update loop…

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement