- Home /
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!!
Answer by Pipioca · Sep 10, 2014 at 02:23 PM
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!
Answer by khenkel · Sep 10, 2014 at 01:48 PM
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;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Font sizes, GUI, Iphones and even more head scracthing problems 0 Answers
Save online states 1 Answer
How to measure ad impressions in In-Game Ads? 0 Answers
A simple ladder in C# or Js 3 Answers