- Home /
Question by
Taplock · Sep 18, 2014 at 02:51 PM ·
javascriptinput
How to make a 3D ball stop rolling as soon as you are done pressing the assigned button
I am trying to make a ball rolling game that has the ball roll along the x-axis and z-axis with jumping. I can make the ball roll either axis, but it becomes difficult to maneuver the ball back from the z-axis and roll it on the x-axis, and vise versa. What I need is a code that makes the ball stop rolling as soon as I press, say the A key, on the respective axis
Here is my code
#pragma strict
var speed : float = 5;
var rotationSpeed : float = 100;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
//Handle ball rotation.
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);
var rotation2 : float = Input.GetAxis ("Vertical") * rotationSpeed;
rotation2 *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.left * rotation2);
if (Input.GetKeyDown(KeyCode.Space) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay ()
{
isFalling = false;
}
Comment
Your answer
Follow this Question
Related Questions
scripting joystick input on javascript 1 Answer
How do I invert the Y axis in Penelope tutorial? 3 Answers
Digging technique counter 1 Answer
Input Get Key Help 1 Answer
Input Axis Mouse ScrollWheel 1 Answer