- Home /
Question by
AmeRevenge · Nov 13, 2013 at 01:11 AM ·
ballz-axisrollrolling
Ball Z-Axis Rolling
Hi guys, I really don't know how the ball that I control can roll in Z Axis can you help me please? Thank you very much :D
pragma strict
var rotationSpeed = 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);
if (Input.GetKeyDown(KeyCode.Space) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay ()
{
isFalling = false;
}
Comment
Answer by Rahazan · Nov 13, 2013 at 03:25 AM
In theory you are not moving it along the Z-axis, the physics engine isn't perfect(ly deterministic) however.
You can lock the position and rotation around axises in the inspector on the rigidbody component. That will fix your problem.
Here's a screenshot: http://i.imgur.com/ORgKl4C.png (at the bottom).
Your answer
Follow this Question
Related Questions
Create a "free" rolling ball controlled by player 1 Answer
How to roll the ball? 1 Answer
How to make a ball that can roll? 2 Answers
iPhone ball roll problem 2 Answers