Creating a Ledge Grab in Unity Part 1!
Objective: Create an object to act a “checker” for the player to know if they can grab a ledge or not.
As with most things in Unity there are multiple ways to get the desired effect you want. In this tutorial we are going to create a checker object above our player and a checker on the platform. When the two checkers collide our character is going to freeze gravity and snap to a position hanging on the ledge.
Download a hanging animation from Mixamo and follow the steps from before to enable us to manipulate the clip. Drag the clip into the animator view. On the inspector view select all three bake to pose options.
For testing create a trigger “LedgeGrab”
Make a transition from Any State to the hanging animation
Set condition to ledge grab
Start the editor, and with the ledge grab enabled create a cube on the player named “Ledge_Grab_Check”
Shape the cube to be as wide as your players hands are. Make it thin and turn off the Mesh Renderer and set is trigger to true.
We’ve created this while in play mode so when we turn it off, everything we created will be reverted back to how it was before we pressed play on the editor.
To Keep the ledge grab checker we can create a prefab. If you don’t have a prefab folder, create one and place the whole player into the prefab folder. Stop the editor, delete the player and drag in the prefab of the player you just created.
We need to determine when is the right time to throw our hands up. Select your ledge and create a cube “Ledge_Checker” and set Is Trigger to true so the two checks can pass through each other.
Position the ledge checker to hang over the edge creating a lip. Widen the the cube to cover the width of the player
Test run and make sure the player’s ledge grab checker can collide with the ledge checker. Adjust their positions and size as you need to, to make sure that when you player jumps for the ledge, the two collide. This is a good breaking point. In the next tutorial we will begin writing the code and giving our character a reaction to the collision! Don’t be afraid to experiment with your game, and I’ll see you in the next tutorial!