Collision detection issue with arcade physics

I’m trying to make a Mario style platformer where you can break/trigger blocks by hitting them from below and this is being a real pain. I have collision detection working fine for the most part, my issue comes with detecting simultaneous collisions between multiple side-by-side tiles.
If my player sprite comes into contact with the corners where two tiles meet, a callback is only made for one of the tiles. I’d prefer it to only trigger for the tile that contacts the center of the player sprite, but it seems to favour the object last added to the group regardless of the position of the player.
A callback is made for both tiles when the player body is a circle, but that comes with other complications I’d rather avoid.

Here’s the collision code in my player class:

this.scene.physics.world.collide(this, this.scene.tilegroup, function(obj1, obj2) {
	console.log(obj1, obj2);
	obj2.alpha = 0.2
});

I’m wondering if there’s a workaround for my issue or if it’s just a limitation with arcade physics. Thanks!

1 Like

:wave:

Collisions are processed one pair at a time, but separations can affect subsequent pairs. So you could do

this.scene.physics.world.overlap(
  this,
  this.scene.tilegroup,
  function (player, tile) {
    if (Phaser.Math.Within(player.body.center.x, tile.body.center.x, RANGE)) {
      // Break
    }
  }
);

this.scene.physics.world.collide(this, this.scene.tilegroup);
1 Like

Exactly what I was looking for, thanks!
I ended up adding tiles to an array on collision that gets cleared each update cycle, so when multiple tiles get hit they can be compared to determine which tile to activate.