Ledge Grab System Part III

Intro

In this short article, we clean up the ledge grab by snapping the position of the player to certain spot when the ledge grab is triggered.

Setup

Move the player to find the position where it looks like the player is grabbing the ledge. Write the X ,Y & Z coordinates down for the code.

The Code

In the Ledge script, we are going to create a Vector3 variable that will hold the position of the hands we want when the ledge grab is triggered. We want to give it a serialized field attribute, so we can place the X,Y & Z coordinates we wrote down from before.

In the Inspector, we will input those coordinates.

When we call the GrabLedge method from the Player, we are going to pass in Vector3 parameter that will be our hand position.

In the Player script, looking at the GrabLedge method we will create a Vector3 parameter call it handPos. We will set the Players transform.position to the Vector3 position it is receiving from the Ledge script.

Conclusion

This was a short article and was heavy on coding, but the result of this position snapping makes for a much smoother transition from jumping to grabbing. Until next time…Cheers!

--

--

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