Nerd For Tech
Published in

Nerd For Tech

2.5D Game Development: Animations: Part 3 — Ledge Grab System

In this article I’ll go over how to set up a ledge grab system.

First I needed a simple animation for hanging from the ledge.

After I got that all set up I needed to determine what animation I’d be most likely transitioning from. Running Jump is the most likely place, so I set up some conditions in the transition from running jump to hanging idle.

As you can see here, I set a condition called “LedgeGrab” to true to initiate the transition. So now the question is: When do I set this to true in the code?

I actually set up a couple of trigger colliders. One on the actual ledge and another just above the player’s head. I actually positioned the one above the player in such a way that the player’s hands are touching it.

Collider over player and its properties
Ledge collider and its properties

As you can see I made a new script and attached it to the ledge collider. Lets check it out.

Ill get into the hand position and stand position variables in a bit. For now I want to check for collision with the Ledge_Grab_Checker and call the helper method create din the player script.

This method sets onLedge to true, disables the controller and sets the bool we created in the animator to true which triggers the animation. I want to update the position to the hand position. So I needed to pause the game once the animation triggered and then scoot the player close to the edge of the ledge so that the player’s position snaps to the ledge.

I gave the handPosition and standPosition serializefield attributes so I could adjust those in the inspector.

So then I needed to have the player be able to pull them self up by pressing E. So this was rather simple and straight forward.

Find a climb up animation, add it to the animator. Obviously you’ll only ever need to use the climb up animation when exiting the hanging Idle animation, so create a transition from there.

I set up a trigger condition for this one.

Easy enough. But when the player climbs up, the character controller is still disabled from when hanging was set to true. So I need to reactivate it at the player’s position once they are standing.

I set up a ClimbComplete function in the player script.

This sets the position of the player to the standPosition we determined in the LedgeGrab script using the GetStandPos() helper method which simply returns the standPosition.

On the climbing animation I added a behaviour script. This script handles specific things during specific parts of the animation. I wanted the character controller to stay deactivated, but move to the player’s new position, so the script below helped with that.

So once this animation is complete it calls the ClimbUpComplete() method inside the Player Script.

Then I transitioned from that to a stand up animation. Once it finishes the character controller is reactivated through the StandUpComplete() method in the player script.

So now I can run, jump, grab the ledge, press E, climb up, stand up, then start moving again!

In the next article I’ll go over how to set up a roll animation for when you press the Left Shift key.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store