LAZR.PW
Stuff I'm working on.

Thursday, 13 February 2014

Unity Trigger Based Ladders

I saw several stackoverflow post and thought I'd share the solution I reached when trying to create ladders in Unity. This post will contain no code, however I hope my explanation and this demo video will be enough to get you started.



This implementation is similar to the ladders in Minecraft, in that as you continue to move towards it you stop applying gravity and climb up it, and when you are at rest, but still colliding with it, you slowly drift down it.

The approach is basically a trigger region that covers the area that you would like to be able to climb from around the actual ladder you are displaying visually.

You'll need to add a climbing condition to your character controller, so that you can toggle gravity and the way your controls work when you are in the climbing region. Then for your forward moving when climbing add an upwards force.

Possible improvements might be to lower the amount of forward movement your character makes whilst climbing the ladder to reduce the sliding on the ladders surface, and to make the "upwards force" actually follow the "transform.up" so that you can put your ladder at all sorts of crazy angles.

This ladder solution can be jumped to and from at any point up it. If this is not desired then you'll need start and end triggers for your ladder, and limited movement(or a whole new movement method) in between the top and the bottom of it, but it's not that much more complicated than this.