- Home /
Implemeting climbing ladder in unity 2d
I am trying to implement ladder climbing functionality in unity and i have achieved it to some degree.I have put circular collider on the top of the characters head so it detects when the ladder is above his head. what i want to do is that if i press the upward key it only climbs one step of the ladder and stays there..But instead the character falls as soon as i stop pressing the upward key and keeps going up if i press it one time..I have messed with the gravity of the rigidbody but no luck.
void Update() { if((isgrounded || !doublejump) && Input.GetKey(KeyCode.Space) ) { anim.SetBool( "Ground",false); rigidbody2D.AddForce(new Vector2(0,jumpforce)); if(!doublejump && !isgrounded) doublejump = true; } if(Ladder && Input.GetAxis("Vertical")>0) { rigidbody2D.gravityScale =0; rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x,Input.GetAxis("Vertical")*maxspeed); } if(!Ladder) { rigidbody2D.gravityScale =1; } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613163122im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Climb ladder 2 Answers
2D Ledge Climb, post climb animation doing wierd stuff (applying player offset). 1 Answer
Distribute terrain in zones 3 Answers