2.5D Platformer — Ledge Grab & Climb #9

No height is too high!

I recently made a *very* basic implementation of a Ledge Grab and Climb which allows my character to reach high places easily. This implementation allowed me to understand the process behind this feature and allows me to create a more polished implementation of it. So I thought this would be worthy of being in an article.

Also, there’s a bit of a time skip between this article and the last one, but you didn’t miss much as all I did was just setting an animator controller for the character. Sorry about that.

The Logic Behind It

To give information to our character controllers about their surroundings, the easiest way to do it is by casting some rays or SphereCasts around them. First, the controller checks for a collider in front of it while it’s in the air, and then, it checks if it’s possible to climb up that collider and if there’s enough space for the controller.

Ultra-minimalistic illustration. I’m quite an artist myself /s

The (Basic) Implementation

I’ve decided to go for another implementation, which requires two new scripts, and two new GameObjects: a ledge checker trigger, and a ledge trigger. I won’t need to code any Raycasts, at the cost of making a dirty, fast, and cheap ledge grab and climb.

You’ll want to create and adjust a new Cube to fit your character’s hanging animation. Set the collider to trigger and add a new tag (name it something like “LedgeGrabChecker”).

The ledge will also be a cube with a trigger collider, but this one will have a Ledge script. When the LedgeGrabChecker collides with it, it will call a method within the Character Controller I named LedgeGrab.

Let’s see how this works…

Not too bad. Doesn’t look that great, but keep in mind that the animations aren’t that compatible with eachother and this implementation doesn’t allow too much room for improvements. However, for a small project or game, it’s “fine”.

Moving on. The next step is to make the character climb up the ledge with an animation and block any input until the controller has finished climbing up.

So, how can we tell the controller the climbing up animation has finished so we can start moving again? With a new Animator Behaviour script! You can create a new one by clicking on Add Behaviour in one of your animation blocks.

This script will auto-generate code blocks with commentated methods. You’ll want to remove everything except the OnStateExit method, which will signal the controller as soon as the Climbing animation finishes.

And now, in the LedgeClimb method, offset the position of the character controller to move it approximately where the character’s model is, and reset the OnLedge and Climbing states.

If you properly set it up (unlike I did), you can skip this offset by applying root motion. Though you’ll need to disable the character controller to avoid weird collisions while the animation finishes.

And, with this, the ledge grab and climb is finished! You’ll have to adjust some values to fit this implementation to your assets and your liking, but you should be set to use this in your game.




Junior Unity Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

PHP 7.4 released! How Badoo Upgrades

JavaScript for Dummies — Part 1

Engineered from the ground up

4 Tips for Solo QA Engineers

Managing Cloud Services via Kubernetes CRDs

7 Common Signs You Need to Outsource Your Project

From a simple SPA to a multi-functional PWA. Smart way to "minimum Full Stack".

Class and object in java

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
Pablo Gómez Platón

Pablo Gómez Platón

Junior Unity Developer

More from Medium

NFT Archaeology and the Digital Art Revolution with Adam McBride

The Global Search for Education: Director Nacho Ros Bernal Explores Loneliness, Abandonment and…

DefiKingdoms — a part two deep dive into the Gaia metaverse

Resolving Issues Before Moving Forward