How to set up a ledge grab system for platformer in Unity

Niklas Bergstrand
3 min readDec 31, 2021

--

Let’s go over how to add a ledge grab system to the platformer project.

I am continuing to add to the Player script from this article. Animations in the article are from Mixamo.com.

First, add a collider to the player which will be used to detect ledges. Set the collider to IsTrigger and the tag to “Ledge”:

On the platform, add a similar collider together with a RidgidBody:

Add two more boxes to the platform. One for where the player will have the feet while holding on to the ledge and another for where the player will stand after climbing up:

Create a script called LedgeGrabber and attach it to the collider on the platform:

Open the Player script. Add a bool to check if the player is currently grabbing the ledge. Also add a Vector3 for the position of the player after climbing up:

In the PlayerMovement function check if the E key is pressed while the player is grabbing the ledge and if so, trigger the climb animation:

Create two public functions, one for handling the ledge grab and another for handling the climbing:

Open up the LedgeGrabber script. Add two serialized Transforms for the positions. Add an OnTriggerEnter function, and if the ‘Ledge’ object on the player is detected set the player’s position:

Open up the Animator window and set up the animations as shown in the screenshot below:

Select the Climbing animation state and add a behaviour:

Open up the behaviour script. In the Exit event call the SetClimbUpPosition on the player:

Lastly, drag the transforms on the platform onto the LedgeGrabber script on the inspector:

Good luck!

--

--