Nerd For Tech
Published in

Nerd For Tech

Creating A Ledge Grab in Unity

2.5D Game Development

Objective: Create a ledge grab feature in the game.

To start off, lets create a cube gameobject and define its transform properties to make it look like a ledge, place it at the position of the grab which is in the player hand and set the trigger to active. Then disable the mesh renderer so that it doesn’t show during gameplay.

Do the same on the ledge where the player is going to hang. This will detect the cube at the hand of the player when it touches itself and position the player to the ledge grab position.

Here, you set two position, one to set the player position to when hanging on the ledge and one to the position after the animation to climb the ledge completes.

This is the script for the animation trigger where the ledge collider checks if the collided object is ledge checker and if true then calls the PlayLedgeGrabAnimation method and provides the player grab position and reference to current script as parameters.

Here, in the called method inside the player script, you basically control all the float and bool value of animation parameters to start the ledge garb animation.

Then you can prevent the movement when ledge grab and if the player presses the E key during that time then the animation changes from hanging to climbing.

Then select the Climbing animation event on the animator panel and select add behavior and create a behavior script.

Then inside the behavior script, we define what happens after the animation is complete i.e. stop climbing animation

Then from the called function inside the player script, transform the collider position to the climbed position and enable the controller so that player can move.

This is our animator to control the animations. you create a set of conditions which if fulfilled will start your desired animation.

And this is the final result.



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