Creating A Ledge Grab in Unity — Part 2: Stop player movement on ledge collision.

Objective: detect the collision between the ledge checker and the ledge and stop the player movement.

In the animator controller attached to the player I added a new animation for the hanging action and a bool parameter to make the transition.

In the player controller I created a new method to trigger the hanging animation and disable the character controller component. By disabling this component we stop the player because it controls the gravity and movement.

In the ledge grab checker script attached to the ledge checker in the player we have to use the OnTriggerEnter function to detect the collision, then we check for the ledge tag and call the GrabLedge function in the player script.

And that’s it. Now the player detects the ledge and stops its movement.



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