Journal 81 — Unity 2.5D Platformer, Add Ledge Grab

Chris Nielsen
4 min readSep 1, 2021

Objective: To add a ledge grab system

In the previous articles, we added a 3D character and environment assets to our basic platformer setup, and we added animations for idle, running, and jumping. Now we want to add a ledge grab system.

Hanging Idle

We can start with Adobe Mixamo and look for “ledge”, and find a hanging animation.

After importing to Unity with “Humanoid” Rig selected, we can pick the animation and duplicate it (Ctrl+d) so it is editable. We can also change the model in the Preview window.

Let’s add this animation to the animator window so we can test the position when he’s hanging from a ledge.

Ledge Grab Check

In Play mode, we can add a cube as a child of the Player that can function as a ledge check.

Then, since we want to save all these changes while in Play mode, we can make a prefab of the Player with ledge check.

Ledge Checker

Now let’s add a cube that will serve as a ledge check for when to implement the hanging animation. Make sure the cube is set to Trigger so you do not bounce off the ledge check.

We can check the size of ledge check to see when the Player jumps, would a collision occur. We may need to eventually modify the sizes of the box colliders to make the transitions as smooth as possible.

Ledge Grab Implementation

Let’s first add a RigidBody to the Ledge_Grab_Checker on the Player. When the Player jumps and triggers the Ledge_Checker collision, we want to disable the Character Controller in order to freeze the Player. We can also turn off the Mesh Renderer on the Ledge, and add a tag to the Player’s Ledge_Grab_Checker.

Next we create a new C# script on the ledge. We can check for a collision with the player’s ledge grab object, then get a reference to the parent (Player), so then at the ledge, we can disable the Character Controller and freeze the Player.

Now let’s add the hanging animation to the Animator.

We can update the GrabLedge function to set the animation bool true.

Here are the results.

Next we can fix the snap position of the player so it looks more accurate where he grabs the ledge. We need to move the player in play mode and find his position, record that, and then when the player grabs the ledge, we can pass that Vector3 position and update the player’s position.

Let’s update the Ledge script with a Vector3 variable to store the player’s hand position, and then we can pass this variable to the player script and update the player position.

Now we can see this in action.

As you can see, the transition and snap to the ledge is not quite fluid. We can adjust the transition duration and the position of the ledge grab collider.

Thank you for your time!

--

--

Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.