hey everyone!
I am creating my endless runner at the moment and I have
coded a double jump.
However the wierd part is is when my character falls of the
platform I can only jump 1 more time.
So basically if I am grounded I can jump 2 times. But if I start
jumping when I am not grounded(aka when I am first falling and then
decide to jump) I can only jump once more.
Here is my code:
void FixedUpdate () {
move += (1f/500f);
if(move > 14) {
move = 14;
}
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
anim.SetBool ("Ground", grounded);
//if game over. Stop moving.
if(GameOver.GameOver == false) {
rigidbody2D.velocity = new Vector2(move, rigidbody2D.velocity.y);
}
}
void Update() {
if(grounded) {
jumping = 0;
}
if(Input.GetKeyDown (KeyCode.Space)) {
Debug.Log ("test");
jumping+=1;
if(jumping < 2) {
//play jump sound.
audio.Play ();
//make velocity equal to 0.
rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x,0);
//character jumps
rigidbody2D.AddForce(new Vector2(0, jumpForce));
}
}
}
Thanks in advance^^!