- Home /
Strategy for "perfect" ladder movement?
Hi, everyone,
My problem has nothing to do with code I don't think, but rather with the approach to solving the problem. I have been developing my own raycast controller for the past few weeks, and one of the last features I want to implement is ladder movement. I have been successful overall in doing this, but the one issue I can't seem to solve is that once my character is about to be off the ladder and land on the platform above to which he is climbing he "bounces" very briefly, though not very high in the air, and then falls flush on the ground. This isn't a big deal, but I want to learn how to make "perfect" ladder movement like you see in most games.
If anybody has input or a strategy to solve this I'd appreciate it. The way my code works is:
If the character is pressing up he emits a raycast from the center of his collider.
Using OnTriggerStay2D (with the condition that the raycast from #1 has hit the ladder already):
If this raycast collides with a ladder the character is now in "ladder climbing mode" and can move up and down using Unity's vertical axis. Gravity is also set to 0 so he doesn't fall.
If the character's raycasts hit the ground while he is moving down the ladder everything resets back to normal. - If the character holds left or right while on the ladder he can jump in that direction.
If the character moves upward, he will go through the 1-way platform I have created, and then land on it, sometimes landing perfectly flush, but most of the time moving slightly above the platform before falling back down, making it look like he's "bouncing." This also resets everything to normal of course.
Perhaps this isn't the best solution, but it works for me. I have literally put around 60 hours into trying so many different ways to solve this issue, rewriting my entire ladder code numerous times, and maybe I'm making too difficult on myself, but I cannot figure it out. It seems like the momentum of the vertical axis is causing the bounce because if I make my movement speed higher there is a noticeable increase in the bounce. However, turning gravity back on and removing the ability to move up and down as soon as the player is no longer on the ladder (which seems like the correct solution) seems to take about .05 seconds, so the bounce still occurs about 50% of the time.
I think the true solution is to limit Y movement via raycast, but I don't know how to do this while going upward since my character has to be slightly inside the 1-way platform collider before moving all the way up the ladder.
Here's a short excerpt of the Platformer Pro asset on the asset store that does what I'm talking about.
Your answer