Check overlap full width

Hello guys. I’m writing a platformer game. I use arcade physics. I have done multiple layers in tiled editor. One of them contains of ladders. I’m checking the overlap between a player and a ladder. So even if my player’s sprite touches 1 px of a ladder’s tile I’m able to climb. I want to compare width of my player and the ladder and only if they 100% overlap player should be able to start climbing. I’m not sure how to realize it. Or maybe there’s some other methods.

https://platformergametest.000webhostapp.com/ here’s the game

  1. optional: enable arcade physics debug option debug: true

  2. in overlap’s documentation it says that it can take an optional parameter, called processCallback that lets you perform additional checks against the two objects if they overlap.

so you probably need to modify your overlap call. e.g:
overlap(player, ladders, collider, isInside, this)

where isInside is a function that will perform the additional checks that you want

1 Like

Thank you! Here’s what I did (maybe it would help others):

this.player.setOrigin(0.5, 0); // I've centered player's anchor

this.laddersLayer.setTileIndexCallback(29, this.allowClimb, this); // I'm allowing player to climb when he overlaps the ladder

allowClimb(sprite, tile) {

        let distance = Math.abs(this.player.x - (tile.pixelX + tile.width / 2)); // I haven't found how to reassign tile's anchor so I just added half of it's width to it's x coordinate
        console.log(this.player.x, tile.pixelX, distance);
        if (this.cursorKeys.up.isDown && distance <= 3) {
            this.player.x = tile.pixelX + tile.width / 2;
            this.player.anims.play('playerClimb', true);
            this.player.setVelocityY(-gameSettings.playerSpeed);
        } else if (this.cursorKeys.down.isDown) {
            this.player.anims.play('playerClimb', true);
            this.player.setVelocityY(gameSettings.playerSpeed);
        } else {
            this.player.setVelocityY(0);
        }
}
2 Likes

Glad I found this topic, been trying to do the ladder for quite a while…

this.laddersLayer.setTileIndexCallback(29, this.allowClimb, this);

The 29 is the tile id or the ladderLayer id ??

I tried both but still not working…

I open your link and viewed your source codes, I found u added overlap() inside the update() instead of create(), any reason why ??

update() {
        this.physics.overlap(this.player, this.laddersLayer);
}

Here is my code on https://pastebin.com/1WpL6pyq , hope you can help me take a look and give me pointers where I gone wrong…

Thanks