My journey becoming a Unity game developer: 2.5D Infinite Runner-Ledge Grab System-Pt2

Rhett Haynes
4 min readJan 26, 2022

Objective: Create a Ledge Checker game object that will detect if the Player’s Ledge Grab Checker object has collided into it. When it does, the Player’s controller will be turned off to keep the Player paused in the air after collision.

Ledge Grab Checker enters into the Ledge Checker, turns off Player’s controller, and Player in Hanging Idle animation.

To start, let’s create a new Cube game object name Ledge Checker. Place it in front of the ledge the Player will jump to, and Scale it to the width of the ledge area that the Player will have to jump and grab onto.

Ledge Checker game object created, scaled, and positioned in front of a ledge.

Play the game and jump over to the Ledge Checker object. See if the Ledge Grab Checker attached to the Player collides into the Ledge Checker. If not, see if you need to reposition the Ledge Grab Checker object a little more in front of the Player’s Hanging Idle hands or Scaling the object to be a little wider.

Testing to see if the Player’s Ledge Grab Checker collides with the Ledge Checker.

In the Player script, we’re going to cut and paste all of the code in the Update() function and place it in a new method name CalculateMovement(). Then back in Update(), use the CalculateMovement() method to handle the Player’s movement just like before.

Player’s movement code removed from Update(), and placed in the new CalculateMovement() method.

Also in the Player script, create a new method name GrabLedge() which will disable the Player’s controller by using the controller variable with the enabled() method being set to False.

Player’s controller turned off in the GrabLedge() method.

Create a new script name Ledge which will use the OnTriggerEnter() method. Inside the method we will check IF the other game object’s Tag equals Ledge Grab Checker. If so, get the Player’s component which is a Parent by retrieving the game object’s transform of the parent. Check IF the Player isn’t NULL, and have the Player use the GrabLedge() method to pause the Player in mid-air after its Ledge Grab Checker collides into the Ledge Checker.

When Player’s Ledge Grab Checker enters the Ledge Checker, the GrabLedge() method is called.

Select the Ledge Grab Checker game object, and create a new Tag name Ledge Grab Checker. In the Box Collider component, make sure to turn on Is Trigger to allow the Ledge Checker to enter into its collider. Last, add a Rigidbody component with its Use Gravity turned off.

Ledge Grab Checker with Is Trigger turned on, Rigidbody added, and Ledge script attached.

Select the Ledge Checker object, turn on the Is Trigger setting under the Box Collider. Also, drag the Ledge script onto the Ledge Checker in the Inspector to create a Ledge script component.

Is Trigger turned on and Ledge script attached to the Ledge Checker.

Play the game and jump over to the Ledge Checker object. If the Ledge Grab Checker collides into the Ledge Checker, you will see the Player paused in the air as its Character Controller is now disabled.

Player’s controller turns off when the Ledge Grab Checker enters into the Ledge Checker.

In the Animator, delete the transition between Any State and Hanging Idle. Create a new transition from Running Jump to Hanging Idle. Create a Bool Parameter name Ledge Grab and click on the transition between Running Jump -> Hanging Idle. Turn off Has Exit Time, leave the Transition Duration setting for now, and set the Condition of Ledge Grab equals True.

Hanging Idle animation transitioned with the Running Jump animation using the Ledge Grab SetBool equals True.

Back in the Player script, in the GrabLedge() method we will add the anim variable to SetBool the LedgeGrab parameter to equal True.

Using the Animator’s SetBool to set the Ledge Grab to True.

Play the game and jump across to the Ledge Checker object. When the Ledge Grab Checker object collides with the Ledge Checker, we will see the Player hanging from the Ledge Checker.

Hanging Idle animation plays when colliding into the Ledge Checker.

Let’s turn off the Mesh Renderer of the Ledge Grab Checker and Ledge Checker objects to remove the appearance of the cubes onscreen.

Mesh Renderer turned off for the Ledge Grab Checker and Ledge Checker game objects.

Now we can see the Player hanging onto the Ledge Checker object even though its transparent.

Player in the Hanging Idle animation grabbing the Ledge Checker object.

Next time we will have the Player hang onto the ledge itself in its Hanging Idle animation, then climb up when pressing a special key.

--

--