Multiplying my "Jump" *2 to make a Double Jump?

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
public float speed = 1f;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

// Basic Movement:

if (Input.GetKey (KeyCode.D))
transform.position += new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);

if (Input.GetKey (KeyCode.A))
transform.position -= new Vector3 (speed * Time.deltaTime, 0.0f, 0.0f);

if (Input.GetKey (KeyCode.Space))
transform.position += new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);

if (Input.GetKey (KeyCode.S))
transform.position -= new Vector3 (0.0f, speed * Time.deltaTime, 0.0f);
}
}

How would I get a second jump to register after the first one? Is there a command to call on my first if(Input.GetKey(KeyCode.Space)) to multiply by two if the GetKey is pressed again in a quick succession? Any help is appreciated, thanks!

put a timer in, on first space key hit, setting a bool to be true. This remains true until the time limit, half a second or so it true, or if player presses space with in that time frame. If he does press space while bool is true, this signifies a double jump. As such, apply the appropriate force.

1 Like

This makes sense. I have no idea how I would implement this though. Is there a source I can learn how to do this from?

Use a coroutine,
or use something like this:

bool doubleJump = false;
Vector3 playerVelocity;

void playerJump()
{
     If (spacebar pressed) && (transform.position.y == 0 || doubleJump))
     {
         if (doubleJump)
           doubleJump = false;
        else if( transform.position.y != 0 )
           doubleJump = true;

        playerVelocity.Y += 5;
     }
}

void playerMove()
{
   transform.position += playerVelocity;

  if(transform.position.y = 0f) //If on the ground, dont apply gravity)
         playerVelocity.y = 0f;
}

void update()
{
   playerJump();
   playerMove();
}