- Home /
Simple ladders script - what am I doing wrong?
Hey
I'm trying to write a script that will allow my first person controller to climb ladders that are set at about 80 degrees. I'm not too bothered about realism I just want it to work so that the game can be played. I have tried 3 or 4 different ways to write a script but I've not managed, and on one occasion wrote one that crashed unity every time I previewed the game! Here is my latest attempt - can you see where I'm going wrong?
private var controller = GetComponent(CharacterController);
function OnControllerColliderHit (hit : ControllerColliderHit) { if (hit.gameObject.tag == "ladder") { climb(); } }
function climb() { controller.slopeLimit = 90; }
@script RequireComponent(CharacterController)
I'm not entirely sure what I'm doing as I've just looked at a couple of other scripts and tried to piece together how to control slopelimit. But basically I need the slope limit to be set at 45 unless the player is touching the ladder, whereby I need it to be 90.
I could do with an answer quickly as I need to finish this today!
Thanks!
Is the ladder properly tagged? Does the character or the ladder have a non-kinematic rigid body? Have you tried making the ladder out of steps ins$$anonymous$$d of one smooth plane? (Character controller can walk up steps) Have you tried putting a trigger above the ladder ins$$anonymous$$d of using on collider hit?
Ah thanks, I'll just make some invisible steps ins$$anonymous$$d of doing it in code. Didn't think of that. Thankyou!
Your answer

Follow this Question
Related Questions
Third Person Controller Issues With Attack Animations NOT Being Found!? 2 Answers
Airplane controller for game object? 0 Answers
Ladder script not working? 0 Answers
2d Platform Controller Face Help 1 Answer