- Home /
Question by
SnowiNinja · Jul 28, 2014 at 09:31 PM ·
variablefunctionfloatball
Ball not going to directions
Hi, i am new to unity and i dont know how to make the ball (object) to go in different directions. I am trying to make it so that you use the WASD keys and it controls the balls. But when i use multiple keys at once, the ball's movement gets kinda random. Here is my script. Thanks.
pragma strict
var rotationSpeed = 100; var jumpHeight = 8;
private var isFalling = false;
function Update () { //Handle ball rotation left and right var rotation : float = Input.GetAxis ("Vertical") rotationSpeed; rotation = Time.deltaTime; rigidbody.AddRelativeTorque (Vector3.left*-1 * rotation);
//Ball rotation up and down
var rotation02 : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation02 *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation02);
if (Input.GetKeyDown(KeyCode.Space) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay () { isFalling = false; }
Comment