Ledge Grab System: Part II


In this article, we will continue to build upon our ledge grab system by creating a game object attached to the platformer that will detect the ledge grab checker we attached to our player in Part I.

Ledge Checker

In the platform game object we are going to add a cube game object and name it Ledge_Checker.

We want to position it to where we would want the Ledge Grab Checker to collide with the Ledge Checker, which will trigger the Hang Idle animation. The position will need to be tinkered with until we are happy with how it looks.

When these two objects collide we will need to identify them, so we will tag the Ledge Grab Checker.

Also, for the Collision Trigger to work one of the objects will need a Rigidbody so we will add one to the Ledge Grab Checker.

The Code

We are going to create a script for the Ledge and use OnTriggerEnter to detect when the Ledge Grab Checker game object has collided with the Ledge Checker. When that happens, we will want to access the player controller and disable it so it turns off gravity.

To access the player controller we need to get a handle on the Player script. We’ll create a variable called “player” and get the Player component via the Collider other. We need to go through the transform and the parent of the Ledge Checker to get the Player script since the Ledge Checker is its child.

In the Player script, we clean it up by moving the movement code into a method.

We will create a new public method called grabLedge. We want it to be public so we can call it from the Ledge script. This method will simple disable the player controller which will stop it movement.

Back on the Ledge script, we will null check the Player component and if we grabbed it we will call the GrabLedge method from the player.

For the animation, we will move the Hanging Idle animation from Any State to Jump. Also, we will delete the Trigger parameter and replace it with a bool parameter. The condition to have it transfer from the Jump to Hanging will be the bool parameter GrabLedge be true.

All we have left to do is set the parameter true in the script. We will do this in the GrabLedge method.


It looks rough now, but the goal was to have the collision between the two ledge detectors, to stop the player in mid air and play the hang idle animation. In the coming parts, we will be able to pull the player up by pressing a key and resume player controls.




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

Recommended from Medium

Cloud Backup Vs. Cloud Storage and How They Ensure Business Continuity

Skyliner and Github Deployment Status

All you need to know about SPF, DKIM and DMARC

Deploying Fast and Secure Web App on AWS Part 3: Caching

The 4-Step Plan To Make Yourself Invaluable at Work

A group of three engineers working with a fourth person to help him out.

AWS tips and tricks to optimize cost and performance for better ROI

How Spikes help to Improve your Agile Product Delivery

Scrum team uses Agile spikes as a time box to research on a user story for the purpose of estimating the agile user story.

PicoCTF — Information

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
Ryan McCoach

Ryan McCoach

More from Medium

Player Jump in Unity

Creating an emission map texture

Platformer: Ladder System (Fixes)

Installing Probuilder In Unity