Creating a Ledge Grab System (part 3)

Snapping in place and Pulling your character up.

Now that we have our hanging animation in place we need to set up the position so it doesn’t look like our player is hanging in mid-air. To do that we will need force the position to the player so it snaps in a desired location when hitting the edge.

Scripting the Snap:

In the ledge script we need to make an serialized field variable to handle the vector3 position we want for our player to snap too. We need to serialized it so we can access this data within the Inspector for ease of adjustment later on.

Next we need to force the placement of the player only when the player collides with the ledge checker, so within the IF statement under the On Trigger Enter method, we will add a the ledge position variable we just created earlier.

In the player script we need to apply the ledge position in the public method by using Vector3.

Then we add the forced position within the method, by using Transform.position = _LedgePos.

Now we will snap to once place when our colliders make contact.

Adding an Extra Animation:

As an extra step, I personally decided to add in an extra animation during the jumping and ledge hang, and that is the bumping of the character when making first contact.

I used another animation aided by Mixamo, which I downloaded and imported to the Animator.

In the Animator, I used the jumping to hanging animation before the actual hanging animation. I set the conditions that used to belong to the hanging state to the Jump to hang state. Then the Hanging state is just a non-condition transition. Just make sure that the jump to hang is not set to loop, since we only want to happen once then transition to the hang.

The end result should look very smooth, if you find that the position is slightly off, adjust it within the Ledge checker where we set the Vector3 variables.

The end result should look like this.

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

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

Recommended from Medium

Adding Background Music

Adding logging to your lambda in a rush

Mobile Game Progression

Reading CSV with Jackson

Server-Sent Events in FastAPI using Redis Pub/Sub

Finishing Up Saverlife

Update from Core Team — January 22, 2022

Disney+ Day is Tomorrow! Watch Disney Content in AR

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Creating a Loot System (part 2)

Creating a Homing Projectile

3rd Person Controller Using Cinemachine Virtual Camera On Mobile

Install Unity’s new input system