Collisions Not Firing?

Hi!

I am trying to use collision detection in a phaser3 game, the callback function doesn’t seem to be firing.

First, in my scene I add two sprites:

playerFish = this.physics.add.sprite(
      this.game.scale.width / 2,
      this.game.scale.height / 2,
      'fish').setOrigin(0.5) 

const plankton = this.add.sprite(20, 20, 'plankton')

Then, I add the code for collision detection:

this.physics.add.collider(playerFish, plankton, () => {
    console.log('collision!')
}, 
null,
this)

I also tried changing “collider” to “overlap” but still not having any luck. I would expect the callback to be triggered and the text “collision!” to be logged to the console, but for some reason nothing happens when these sprites overlap. :thinking:

Am I missing something else here to set up the collision detection? Thanks!

plankton has no body. Use this.physics.add.sprite() there as well.

2 Likes

ah, good catch. thanks!