Creating A Ledge Grab in Unity

my player now jumps and moves with animations, now I want him to be able to hold on to an edge that he can reach by jumping.

Obviously, for the animation, we go back to Mixamo and once we find what we are looking for we add it to our project.

Let’s start right away from our player, insert the animation with a trigger to test the point of support. By creating a cube and modifying it, as if it were actually the point of support of the hands of my animation I am creating what will be the “Ledge Grab Checker” or rather the game object that will recognize a point where it will be possible to hook. Absolutely do not forget to assign a Rigidbody and make the collider trigger.

“Ledge Grab Checker”

Let’s move to the platform where we want to create the possibility to grab. Also here we are going to insert a cube of which we will modify the shape and deactivate the “Mesh Render” to have the collider that will recognize the passage of the player.

“Ledge on the platform”

Now that we have the tools in Unity it’s time to move on to the code.

This time we start with the platform, I have to recognize the “Ledge Grab Checker” of the player, our game object is the son of the player so we should use the keyword “parent” for the call of the “GetComponent” and we are going to call a public method from his class.

In the Player class instead, we have to write the method that will do a series of operations.
- block the game object of the player when it comes in contact with our Ledge
- start the animation
- Snapping the position of the player in the correct position attached to the platform.

We should also fix the other variables of the animator controller.
The method must be public otherwise our ledge will not be able to call it.

And that was the first part. Now we have to figure out how to get up, we’ll find out in the next article.

project manager by day, unity developer by night