- Home /
Jump is registered when falling of platform?
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^^!
Comment
Answer by BabyDev · Jul 14, 2014 at 08:45 PM
I already fixed it myself! Here is my new code: void FixedUpdate () { move += (1f/500f);
if(move > 14) {
move = 14;
}
//if game over. Stop moving.
if(GameOver.GameOver == false) {
rigidbody2D.velocity = new Vector2(move, rigidbody2D.velocity.y);
}
}
void Update() {
if(Input.GetKeyDown (KeyCode.Space)) {
jumping+=1;
anim.SetBool ("Ground", false);
if(jumping < 3) {
//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));
}
}
}
void OnCollisionEnter2D (Collision2D col) {
if(col.gameObject.tag == "GroundSpawn") {
jumping = 0;
anim.SetBool ("Ground", true);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613154042im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to jump multiple times to mid air? 3 Answers
About character doublejumping. 1 Answer
Double Jump? 2 Answers
double jump 2 Answers