Hello guys. I have a interesting case here.
I’m creating a platformer game where there are some platforms that have ladders on top.
When the player gets to the top of the platform the player state changes and the player gets standing (idle) on the platform. Everything working great so far. The problem I have is that the character should be able to climb the ladder down, but the ground tile is not letting him pass.
Everything is achieved by a Finite State Machine for the player so in the Standing State:
if(down.isDown) {
// CLIMBING DOWN
if(player.checkLaddersDown(scene)) { // The checkLaddersDown function check if there is a ladder below the player sprite
this.stateMachine.transition('onLadder'); // Here the problem, not climbing down because the ground collision
return;
}
// DUCKING
this.stateMachine.transition('duck');
return;
}
A look at the onLadder State:
class HangingOnLadderState extends State {
enter(scene, player) {
player.setVelocityX(0);
player.setVelocityY(0);
player.anims.play('onLadder');
player.body.allowGravity = false;
}
execute(scene, player) {
const { up, down, left, right, shift } = scene.keys;
// MOVEMENT
if(left.isDown) {
player.setVelocityX(-150);
} else if(right.isDown) {
player.setVelocityX(150);
}
if(!(left.isDown || right.isDown)) {
player.setVelocityX(0);
}
// FALLING
if(!player.checkLadders(scene)) {
player.body.allowGravity = true;
this.stateMachine.transition('fall');
return;
}
// JUMPING
if(shift.isDown) {
if(Phaser.Input.Keyboard.JustDown(shift)) {
player.body.allowGravity = true;
this.stateMachine.transition('jump');
return;
}
}
// CLIMBING
if(up.isDown || down.isDown) {
this.stateMachine.transition('climb');
return;
}
}
}
I’m not sure if there is a way to maybe disable the collision temporarly or another solution.
Have you ever done something like this? How can I achieve this?
Thanks a lot guys, you are an incredible community.