Creating a ledge grab in Unity

Objective: Create a ledge grab that allows the player to hang on the edge of platforms

One of the last mechanics to set up for the 2.5D platformer is the ledge grab. This system takes a lot of small changes in the editor to get just right for your grab animation.

First, I need to grab an animation that will show that the player is grabbing a ledge. There are a few good ones on Mixamo but I liked the one where the players feet are up and appear to be resting on the wall/platform.

I set up the animation in the animator and adjusted the transition to the ledge grab animation.

Next, I set up the colliders for both the player and the ledge. For your player, add in a box collider or a cube as a child object, when finished scaling the object remember to turn of or remove the mesh component. I had my game in play mode and jumped towards the ledge and clicked pause, then click the next frame button to move the game along at 1 frame at a time. This way I could see where I should position the collider.

Above you can see both the colliders, the top one is on the player and the second is on the platform.

Moving along frame by frame you can see where the boxes collide and where the player will end up.

The player is not quite on the platform but with some clever camera work and moving some of the platform towards the player they will never know.

As for the code for this to work, I created a new C# script called LedgeGrab. All this has is a trigger enter method and communicates with the playercontroller to update the animator.

I have set up a vector that will hold the position that I want the player to appear at when grabbing the ledge, the movement to the position will happen so fast that the player will not see it.

In the playercontroller I created a new method that will change to the ledge grab animation. I pass in the position for the players hands so that the player will move to that position.



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