Creating a Ledge Grab System

Matthew Clark
4 min readJun 3, 2021

Objective: Create a Ledge grab system that will be modular

Ledge Grab Checkers

The first step is to get a checker to detect when the player should be in the ledge grab. Create a cube under your player game object and set it above the player's head. You should have your ledge grab animation in the game so you can line up the checker with the model's hands in the hanging animation.

You can remove the mesh renderer and add a rigid body to the checker.

Note: Create a tag called LedgeChecker

Now you will add a similar checker to the ledge you want to grab. This checker will be marked as the trigger. This checker will also need to be adjusted to get a good snap to the ledge.

Ledge Grab Scripts

Now create a script for the ledge grab and add it to the ledge checker attached to the ledge.

Now start in the player script and create a bool variable for when the ledge grab is active and a variable that will hold a reference to the ledge grab script.

Create a public method that will take in a transform and a ledge grab script. When called it will set the ledge grab variable to true, disable the character controller, adjust the animations that should be playing, set the position of the player model, and set the ledge grab reference to the instance that is passed into the method.

Note: The Parameter names are set up in the Animations section of this article

Create a private method that will check if the ledge grab is false. If it is and the player hits the E key the climb-up animation will play.

Note: This will be called in the update method

Now go to the ledge grab script and create two transform variables for the model position when it is hanging and when it is standing on the platform when the model climbs up.

Using the On Trigger Enter method, check for the ledge grab checker to enter the ledge checker. When it does get a reference to the player script. Call the Ledge grab method and pass in the first transform position and the current script.

Animation Set-Up

Now drag the ledge grab and climb up animations into your Animator. Create two bool parameters for the ledge grab and climb-up animations. Create transitions between the running jump and ledge grab animation and the ledge grab animation and the climbing animation. If the ledge grab is true go to the ledge grab animation. If ledge grab and climb-up are true play the climb-up animation.

Ledge Grab Position

Now duplicate the player and only keep the mesh filter. Get the player in the ledge grab position and line him up with the edge of the platform. Get the duplicate lined up as close to the player as you can. Make sure the duplicate is a child of the platform so we can make a prefab and allow it to be modular. Once lined up delete the mesh filter and only have the transform. Drag this into the ledge grab script for the ledge grab position. For now, create a duplicate of the player, set it up with just the mesh filter, and child it to the platform. Drag this into the other transform position in the ledge grab script. This will be set up in my next article.

Prefab the platforms to allow for a modular ledge grab that can be set up anywhere in your scene.

Now the ledge grab should be working.

In my next article, I will get the player standing on the platform and ready to move.

--

--