2D climb ladder

Hey everyone,

I tried to write a script so climb a ladder. And in my opinion it should work, but it doesn’t :smile:

I put the script on my trigger Object and put my player as characterController. I can see all the Debug.Log outputs, but the character won’t move. Why won’t he move?
Any help is appreciated.

Here’s my code:

var characterController		: CharacterController;
private var climbSpeed		= 10;
private var moveDirection 	        : Vector3 = Vector3.zero;
var isClimbing				: boolean;

function Start()
{
	characterController = GetComponent(CharacterController);
}
function Update () {
				
	if (Input.GetButtonDown("Vertical")){
			Debug.Log("TasteGedrückt");								// check if Button is pushed
				if(isClimbing) {
							Debug.Log("TasteGedrückt und true");	// check if button is bushed and isClimbing is true
							
							
							moveDirection = Vector3(0, 0, Input.GetAxis("Vertical"));
				
           					moveDirection = transform.TransformDirection(moveDirection);
            				moveDirection *= climbSpeed;
							
							characterController.Move(moveDirection * Time.deltaTime*climbSpeed);	// move character
		}
	}
	
}


function OnTriggerEnter(characterController : Collider){
		
	
			if (characterController.gameObject.CompareTag ("Ladder")){
			
			isClimbing = true;
			
				Debug.Log("isClimbing = true");					// character is on the trigger
	}
	
}

function OnTriggerExit(characterController : Collider){
	  
	if (characterController.gameObject.CompareTag ("Ladder")){
		
		isClimbing = false;
		Debug.Log("Weg vom Trigger");							// character is out of the trigger
	}
}

Gravity is true/false???

Gravity is set to 0 in my Vector.

What is LadderTrigger?? Can you tell some more details?

LadderTrigger is the name of my script.

I made an Object and put the tag Ladder on it and set it’s Is Trigger in the Box Collider on true. Then I took the script and puts it on my Object.
I use my Player as characterController.

Now I think I have to put the script on my Player instead of my Object and maby then he’ll move.

I’ve got a feeling, that gravity is still on. How can I turn it of while I’m climbing? Any idea?

I solved my Problem … it works.

I added this code to my move script. And added gravity = 0 in line 17. And now things work.