- Home /
Question by
chathura2020 · Oct 01, 2014 at 09:26 PM ·
c#climbladder
Issue with the c# script for player climb in unity
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?
Comment
Answer by N1warhead · Oct 01, 2014 at 11:31 PM
You could try disabling Gravity until you get to OnTriggerExit then reapply Gravity.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
Climb ladder 2 Answers
Modify tps standard script to be able to climb pipe/ladder 0 Answers
Distribute terrain in zones 3 Answers