Climb ladder

Hi!

I have in my game some ladders and want to try the FPS the rise.

In the ladders i have a cube as a trigger and i have this basic script too:

public float velocidadSubida = 5f;
	bool DentroEscalerilla = false;

	void OnTriggerEnter(Collider hit){
		//Si es el personaje el que esta en la escalerilla
		if (hit.gameObject.tag == "Escalerilla") {
			DentroEscalerilla = true;		
		}
	}

	void OnTriggerExit(Collider hit){
		if (hit.gameObject.tag == "Escalerilla") {
			DentroEscalerilla = false;
		}
	}

	void Update(){
			Vector3 movimiento = new Vector3 (0, velocidadSubida*Time.deltaTime, 0);
			if (DentroEscalerilla == true){				 				
				if (Input.GetKey(KeyCode.W))
				{
					gameObject.transform.position += movimiento;					
				}
			}
	}

My First Person Controller start to climb but then stop and fall to the ground again. If i hold down “W” the character continuously start to up and fall.

What is my error? I’ve also tried with the “OnTriggerStay”.

Thankss!!

First of all you can write:

if (DentroEscalerilla)
{                                
       // Stuff
}

You don’t need to double compare it with “== true”.

About your problem:

How big is the cube? Does it fill the entire ladder “area”? If not, it will call “OnTriggerExit” if you climb too high and exit the trigger.
Also physics are still running while you’re overriding your position. While climbing disable it via:

this.rigidbody.useGravity = false;

I made it!, what the problem was? The gravity but the CharacterMotor gravity not the rigidbody gravity.

The solution? Used when you entry on the ladder

motor = GetComponent<CharacterMotor>();
motor.movement.gravity = 0;

Regards!