Ledge grab

I received a question on Reddit regarding how I implemented the cat's climb to ledge grab transition, so here we go!

  • This article will be about:
    • Working with flat ledges
    • How to determine what is a ledge
    • Creating seamless animation transitions from jump to ledge climb to idle
    • What to do with character's collider during this transition
  • This article will NOT be about:
    • A beginner's guide to Unity or Blender
    • Working with slanted/angled ledges
    • Step-by-step instructions on how this will work in your game
    • Wall scaling or ledge scaling

Determining what is a ledge

There are plenty of ways to go about this. For my game, I wanted to ensure that ledge detection would occur automatically (i.e. does not need manual placement of ledge grabbable areas).


To do this, I use two raycasts that start from around the cat's front paws and shoot out toward a possible wall. One raycast will be positioned slightly above the other. In the above image, the red ray represents the bottom raycast, and the top green ray represents the top raycast (ignore that bottommost green ray).

If the bottom raycast hits a wall but the top raycast does not hit a wall, this means we are at a ledge! You should play around with the raycasts' lengths to see what works best for you. I'd also recommend having the raycasts ignore the player's own collider (you can do this in Unity quite easily through layer masking). You can also use layer masks to determine which objects are climbable. I made sure to include all of this logic within FixedUpdate() to avoid collision tunneling.

Transitioning from jump to ledge grab to idle animation

So now that we know we're supposed to grab the ledge, let's start working on the animation transitions.

Jump last frame Idle first frame

The first image above shows the last frame of the cat's jump animation. The second image above shows the first frame of the cat's idle animation. The goal is to create an animation that transitions between these two poses.

To do this, I create a new animation called Ledge Grab. The first frame of this new animation is a copy of the last frame of the jump animation. I rotate this pose 90 degrees, so that the cat is facing up. I also move this pose's position to be behind and below the original position. This gives some space to allow for a climb animation and is also important for when we move the collider later. The last frame of this new animation is a copy of the first frame of the idle animation. Then in between these poses, I draw the rest of the fucking owl.

Ledge grab anim

Moving collider to top of ledge and playing new animation

We've determined that we need to climb a ledge and have also created a ledge climbing animation. Now, we need to move the collider to its new position and play the animation.

Collider before ledge Collider during ledge

I'm using a capsule collider for the cat. Take note of the position and rotation of this collider in the above two images. In the first image, the cat has not detected the ledge yet. In the second image, the cat has detected the ledge. Upon ledge detection, the cat's game object (including collider) is immediately repositioned to the top of the ledge. Also upon ledge detection, the cat's animation switches to play the new ledge grab animation.

Remember when we moved the first animation pose behind and below its original position? When we reposition the game object/collider upward and forward to be on top of the ledge, we are offsetting what we did in that animation. Because the game object is repositioned simultaneously with the animation change, the reposition is seamless.

If the transition looks worse than desired, you may need to play with the position of the ledge grab animation's first pose.

Collider shift

Feel free to DM me on Twitter or email me at tenthlifegame@gmail.com if you have any questions.

Happy devving!

Previous Post