Ledge Grabbing in Unity

Kyle W. Powers
Nerd For Tech
Published in
3 min readJul 1, 2021

--

This article will show how to create a ledge grab mechanic for the Player to get to the next platform.

In the Animator for the Player we add the animations for the Hanging Idle and Climbing, then we create parameters to trigger transitions to the animations, and make the transitions.

On the Player GameObject we add a Box Collider set as a Trigger with a Rigidbody. This Trigger is what will detect when to change to the grabbing of a ledge.

In the Player script, we need to add a variable to stop the calculation of movement when on a ledge and then check for the ‘E’ key to be pressed and then set the ClimbUp Trigger on the animator.

This method will be called by the Ledge that the Trigger collides with to change the Player’s position to the grabbing position, stop calculating movement by setting the grabbing ledge bool to true and disabling the Character Controller. Then on the animator we set the Parameters to change to the Hanging Idle animation.

Now to create the Ledge to grab. The Ledge script will hold a reference to the position the Player will move to when grabbing the ledge. When the Player’s Trigger enters the Ledge’s Collider we grab the PlayerController script component from the parent and call the GrabLedge method on it passing in the grab position.

The Ledge is made of a Box Collider set to be a Trigger with an empty GameObject for the grabbing position for the Player as a child object.

Now when the Player jumps into the Ledge Collider it will start the hanging animation and move to the grab position.

But if we were to press the ‘E’ key the climb animation will play but then the Player model moves back and idles in the previous position.

In the following article we will use Animator Events to move the Player to a position on top of the platform.

--

--

Kyle W. Powers
Nerd For Tech

Unity Developer, Software Engineer, Game Developer