Creating A Ledge Grab in Unity Part 1

Using Collider Trigger To detect the Ledge

James Lafritz
4 min readJun 21, 2021

Setting the Player Up To Grab onto a Ledge

I added a Hanging Idle animation with a Trigger to trigger it from any state.

Next while in Play Mode I triggered the Free Hang Trigger and added a Cube to my Player. I Resized and Positioned the Cube in the location of my players hands. Since I am in Play Mode this will go away when I exit Play Mode, so I copied the Transform Component Values.

Now I know where my hands will be when I ledge Grab. Now that I am not in Play Mode I add a Cube and past the The Transform Component Values. I also make sure that the Collider is a Trigger. I turn the Mesh Render off.

Giving the Player an Edge to grab on to.

I Identified the Edge I wanted to be able to grab. Scifi Floors Edge 4

I add A Cube called Edge Checker. I make sure that I set the Collider to be a trigger. I then position it at the location of the edge and scale it to make sure it covers enough of the edge.

Next I Play Test this to make sure that they will collide.

Testing Frame By Frame I am definitely going to be able to grab the edge.

Triggering the Ledge Grab

I need to trigger the Ledge Grab. To do this I will be using ScriptableObject Variables. I installed my Core Framework using the Package Manager using add package from GIT url https://github.com/JamesLaFritz/CoreFrameWork.git

I add a Ledge Component To My Ledge Checker.

I start filling out my typical Trigger.

I add in what I want to happen.

I check to see what the trigger collides with.

I want it to collide with the Ledge Grab Checker. I have to add a rigid body for the trigger to work. Correctly.

I added a Ledge Grabber Tag to my Tag list. Now I can change the Checker to check for this tag instead of the Player.

I forgot to Tag the Ledge Grab checker. After I fixed that the system will now work as intended.

I added A Bool Reference for the trigger animation and a Bool Referenc for the Players Gravity

In the Player Animation I set the Ledge Grab Trigger. I also set the value of the ledge grab Bool to false so it does not keep triggering the ledge grab animation.

Now in the Apply Gravity of the Player Behavior I add a check if the player’s gravity should be frozen, If it is then I set the gravity scale to 0.

Now in Unity I create the 2 ScriptableObject Bool and assign them in the inspector.

Now things work sort of.

The issue is that I am adding gravity to the velocity at the end of the Apply Gravity Method. When I set the Current Gravity Scale I also need to set the Velocity on the Y to 0.

Now My Character Can Grab Ledges.

--

--

James Lafritz

Excited about changing my hobby into a new carer with GameDevHQ course.