I am trying to make the player to climb a ladder. (2D game)
I used this code for that,
void OnTriggerEnter2D(Collider2D collider){
if(collider.gameObject.tag=="Ladder"){
_canClimb = true;
_anim.SetBool("Climb",true);
}
}
void OnTriggerExit2D(Collider2D collider){
if(collider.gameObject.tag=="Ladder"){
_canClimb = false;
_anim.SetBool("Climb",false);
}
}
In the update() ,
if(Input.GetKey(KeyCode.UpArrow) && _canClimb == true){
transform.position = Vector3.Lerp(transform.position,ladderTop.transform.position,Time.deltaTime);
}
I have put a child game object to ladder to get the position of the top of the ladder.
But When the player jumps and hit with the box collider of the ladder I can see the climbing animation. And after that the player falls down to the ground again. It doesn't move up. What is the reason for that?