- Home /
Double jump with touch
Hi, i've got some troubles with the jump for an Android app. Here is the code:
void Update()
{
if ((grounded || !doubleJump) && Input.touchCount == 1){
anim.SetBool ("Ground", false);
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x ,0);
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, jumpForce));
source.PlayOneShot(jumpSound,0.6f);
if (!doubleJump && !grounded)
{
doubleJump=true;
source.pitch = source.pitch + 0.5f;
}
}
}
The problem is this: when i touch the screen the character makes only double jump (i think because the update function check almost instantly if there is a touch on the screen, and there is not enough time to lift the finger from the screen and making a double jump because the function detect my previous touch as a new touch). Does anyone kows how to fix this issue? Thanks!
Answer by bananaofdeath167 · Oct 11, 2015 at 11:47 AM
@DamianoDamiano the if (!doubleJump && !grounded) { doublejump = true; } basically says if the character isn't double jumping when you tell him to jump then make him double jump which in this case will always be true
Your answer
![](https://koobas.hobune.stream/wayback/20220612002303im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
Double jump 2D Platformer 1 Answer