Ledge Grab System: Part V

Ryan McCoach
3 min readDec 30, 2021

Intro

In this article, we wrap up the Ledge Grab System by making it modular and easy to prefab.

Setup

As of now, we snap the player’s position to Hand Pos when the player grabs the ledge and when the climb animation is finished, we snap the player to the Stand Pos. This causes an issue when we Prefab this because it is no longer modular. If we were to duplicate the Platform Ledge and were to preform the same Ledge Grab on the clone Platform Ledge, the player would snap to these positions. We could manually enter in new positions each time we duplicate the Platform Ledge, but this will make editing the level tedious.

We are going to create two game objects that will be parented to the the Ledge Checker and the player will snapped to these game objects positions instead of being hard coded.

So, we create a game object that will be the Hand Pos target and one that will be the Stand Pos target. Make sure to remove the Box Colliders and disable the Mesh Renderer to make them invisible.

Code

In the Ledge script, we create two private game objects and give them serialize field attributes.

Since we gave them that attribute, we can now assign them the Hand and Stand target game objects in the inspector.

After null checking the Hand & Stand Target game objects, we set the _handPos & _standPos Vector3s to the respective game objects. This keeps the original code intact since those Vector3s are being called by the Player script.

Conclusion

Now we are ready to make the Platform Ledge a prefab and can duplicate and reuse it throughout the level without having to worry about hard coding the hand & stand positions for each of the Platform Ledges.

--

--