I am making a script that requires an object move while jumping. But when I make the object move to the right and then make it jump, it just jumps straight up. It doesn’t jump to the right, and same for the left. Here is my code:
---------------------------------------------------------------------------------------
#pragma strict
var rotationSpeed = 150;
var jumpHeight = 5;
var jumpHeigtht2 = 0;
var isFalling = false;
function Update ()
{
// this is to Handle the Ball rotation.
var rotation : float = Input.GetAxis("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
GetComponent(Rigidbody).AddRelativeTorque(Vector3.back * rotation);
// this is to help the ball jump.
if (Input.GetKey(KeyCode.W)&& isFalling == false)
{
GetComponent(Rigidbody).velocity.y = jumpHeight;
}
}
function OnCollisionStay ()
{
isFalling = false;
}
function OnCollisionExit ()
{
isFalling = true;
}
-------------------------------------------------------------------------------------
How do I fix this? Can anyone help?