Let It Go — The Ledge, I mean
Objective: implement the possibility to make the character fall from the ledge-grabbing state
With this tutorial, I want to give the player the possibility to let go of the ledge and fall instead of climbing it up. The change should be almost effortless since we already have a logic that takes input to climb up.
We just need to remember that the character stays in hanging position thanks to the brute-force trick of disabling the character controller, and it will stay disabled while the character stays inside the ledge (trigger) collider box.
So, what we need to do is to disable the collider (and re-enable it after a short time for future grabbing), enable the character controller and let the player fall.
R is the key we need to press to let the magic happen. We deactivate the collider and set a trigger parameter that starts the transition from hanging to falling state.
Deactivation and reactivation of the collider are performed in a coroutine using a delay: long enough to allow the player to fall, short enough to make the ledge available again.
The character controller will be safely enabled on falling state enter. This command will be performed every time the character is falling, but that’s not a problem.
Let’s take a look a the result.