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

The Opportunity in App Modernization | WalkingTree Technologies

How to deploy Lambda using Terraform

Should I learn Flutter in 2022? | Learn Flutter from Scratch

The 7 Best Slack Integrations and Add-ons of 2019

Introduction — the Evolution of Function-Specific Software

Self-Service Cloud Orchestration with Cloudify for ServiceNow

House of what? House of gigs!

Flowing with new Constraint Layout — Flow

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

Midnight rant (without context)

Everything about the weakest Currency in the world (Iranian Rial)

A Gamepreneur is Born: One Year in F/MS

2021 11/28