Hello everyone, i’m building a simple platformer and about to add climbing on ladders/vines etc.
The desired behavior for the character is to turn off gravity and y speed once it touches a ladder object.
I make use of the physics arcade overlap function:
this.physics.add.overlap(this.player, this.ladders, function (player,ladder) {
player.onLadder = true;
player.setGravity(null,-300);
player.setVelocityY(0);
},null,this);
Then in the update i set it back to false to reset the onLadder var:
update (time, delta)
{
PlayerMovement(); //do movement on ladder or normal movement (if onladder is false turn on gravity)
this.player.onLadder = false; //reset vaiable so the overlap can be checked next frame
}
This works for the most part, but while staying inside of a ladder object sometimes the onLadder variabel does not get set to true, and thus every other frame the character starts sliding (slowly) to the bottom.
I added a test var, and every overlap call i add to it “test++”.
In the update function i console log the value and set it to zero for the next frame.
every 2 frames it gets called 3 times… while the other 2 frames it does not get called and thus the character gets its gravity back for 2 frames…