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 :smiley:

#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;

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: (at the bottom).