Unable to make ball jump and move same time

Viewed 1095

I am able to jump or move left/right any point in time. But unable to jump and at the same time move left/right simultaneously. Am I missing anything? My codes as follows. Thanks for advice.

public int rotationSpeed = 100;
public float jumpHeight = 8;

private bool isFalling = false;

void Update () {
    // handle ball rotation 
    float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
    rotation *= Time.deltaTime;
    rigidbody.AddRelativeTorque(Vector3.back * rotation);  

    //check input
    if (Input.GetKeyDown(KeyCode.W)) 
    {
        rigidbody.velocity = new Vector3(0, jumpHeight, 0); 
    }
}
1 Answers
Related