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:
JavaScript
x
13
13
1
let avatar = this.physics.add.sprite(
2
localStorage.x ? localStorage.x*1 : 300,
3
localStorage.y ? localStorage.y*1 : 300,
4
"avatar",
5
0
6
);
7
8
let tree = this.physics.add.image(100, 0, "bigtree");
9
tree.setScale(4, 4);
10
tree.setImmovable();
11
this.physics.add.collider(avatar, tree);
12
13
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…