Day 19: Climbing up from the ledge

Philip Johnson
4 min readJul 21, 2021

--

Objective: To have our player play the ledge climbing animation and to snap our player object’s position to the standing position.

With the first part of our ledge grab mechanic complete, we can now focus on making it look like the player is climbing up from the ledge seamlessly. To achieve this effect we need to do a few things:

  • Play the climbing animation
  • Enable the character controller component
  • Snap the player objects transform.position to the desired stand up position

First, we need an animation to work with. Once we’ve acquired the needed the animation we’ll add a new bool parameter called Climb_Up.

This trigger will tell the animator to play the climbing animation if we are grabbing a ledge. Now that we can play the animation of climbing up the ledge we need a way to communicate with the player to enable the character contoller and to snap the player transform to a good position. We need to rely on the climbing animation to tell us when it has completed so that we can use a callback to communicate with the player.

This behaviour is a c sharp script and it inherits from the StateMachineBehaviour class. This basically means if we use the call backs provided with the script template then we can use those callbacks for any animation.

Each animation has an enter, update, and exit call back that we can use to communicate with the player. This override method already gives us access to the animator. We will use the GetComponentInParent<Player>() method to access the player script.

Now that we can communicate with the player we can call it’s public method to stand us up and snap us to a good position.

In our Player script we need to have a reference to the current ledge

After we create the reference to our current ledge, we will take a Ledge parameter in our GrabLedge() method. This will give us access to any public methods the Ledge object has.

If we are hanging onto a ledge we will use the “E” key on the keyboard to trigger the climb up animation which will then trigger the ClimbUpFromLedge() method in the player script.

Our ledge script needs to have a reference to a position for our player to snap to once the climb up animation is complete. We also need to make sure we pass the current ledge into the players GrabLedge() method because we added that paramter earlier. Because the _standPos Vector 3 is private, we will create a public method that simply returns the value of _standPos. We do it this way because the _standPos will most likely be different for each Ledge.

The public Vector 3 will simply feed our player script the value of our private variable _standPos
the player script (seen in the image above) will match its position to whatever the value is from _ledge.GetStandPos()

The completed effect can be seen in the gif above. With this mechanic complete we have everything we need to create the ladder mechanic. I now have the task of merging all of my Player controller logic into one project and piece together a nice simple platforming game that should feel familiar to fans of the genre.

--

--

Philip Johnson
Philip Johnson

No responses yet