2.5D Cert Req: Creating A Ledge Grab

I always wondered how a ledge grab system would work…

Until now, I have finally figured out how. I am sure that there are many ways to go about it, and the route I went with seems simple and logical.

I have a hanging animation set for my player. I also have a child game object of a box that fits perfectly under the player’s fingers when the hanging animation is set. It’s a trigger collider with a tag called “LedgeGrabChecker.”

I also created a Ledge game object where it will detect if the player’s “LedgeGrabChecker” collided with it.

If the player jumps short and the game object with the tag of “LedgeGrabChecker” collides with the ledge, then I want to disable my character controller component to stop movement, and set the hanging animation.

So I needed to create a separate script for the behavior of the Ledge for it to detect the “LedgeGrabChecker.”

public class LedgeChecker : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag(“LedgeGrabChecker”))
{
print(“Player can ledge grab!”);
var _player = other.GetComponentInParent<Player>();
if(_player != null)
{
_player.GrabLedge();
}
}
}
}

When colliding with the trigger, I want to call the GrabLedge method which will disable the character controller component and set “isHanging” to true. The PlayerAnimation script will need to know if it’s true or false to set the hanging animation.

public void GrabLedge()
{
print(“Is Ledge Grabbing!”);
_controller.enabled = false;
_isHanging = true;
}

In the PlayerAnimation script:

private void Update()
{
Vector3 _velocity = _player.GetVelocity();
bool _isJumping = _player.IsJumping();
bool _isHanging = _player.IsHanging();
_animator.SetFloat(“speed”, Mathf.Abs(_velocity.z));
_animator.SetBool(“isJumping”, _isJumping);
_animator.SetBool(“canLedgeGrab”, _isHanging);
}

If “isHanging” is true, then I want to set the hanging animation.

With more time dabbling into the grab ledge system, I managed to get it looking decent provided with the knowledge and assets I have.

With all of this set, I now have a functional working Ledge Grabbing system going! Simple and complete, it’s the basis of something that can be further extended.

Gabriel

--

--

--

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

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

Recommended from Medium

Is it Worth to Hire an Android App Developer?- Top 5 Tips!

Will Lombok survive after Java Records?

How to use webhooks in Strapi

Video Calling Integration Using Agora IO and Socket IO in Flutter.

Explain raw_input() function with example.

The Ultimate guide to Flutter Integration Testing

Slice and Append function in Golang

How To Make Money Online | Earn At Least P15,000 A Month Selling Taho | Smart Parenting Sweldo…

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
Gabriel Perez

Gabriel Perez

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

More from Medium

Using Cookies to Create Realistic Lighting in Unity

Lights and Fog and in Unity’s HDRP

Creating a Sci-fi Lab Room

Working with Unity’s 2D Tilemaps