- Home /
I lose control of my ball?
Let me be more specific...
I'm making a game where you have to move the ball through a maze and pick up points on the way. To control the ball, I am using this code here...
#pragma strict
var rotationSpeed = 200;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
// Handle ball rotation along X azis.
var rotationX : float = Input.GetAxis("Horizontal") * rotationSpeed;
rotationX *= Time.deltaTime;
rigidbody.AddRelativeTorque(Vector3.back * rotationX);
// Handle ball rotation along Z axis.
var rotationZ : float = Input.GetAxis("Vertical") * rotationSpeed;
rotationZ *= Time.deltaTime;
rigidbody.AddRelativeTorque(Vector3.right * rotationZ);
// Controls jumping.
if (Input.GetKey(KeyCode.Space) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
function OnCollisionStay()
{
isFalling = false;
}
Whenever I try to control my ball, one axis will work absolutely fine but when ever I try to control the other axis, the ball loses control and I can't stop the ball as I can't control the rotations. If anyone can tell me what has gone wrong and how to fix it, I would be very grateful. Thank you in advanced :)
im not sure if you did, cuz i don't know much about coding (thats why this is a comment, not an answer) but check if it's global rotation and not local
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Rotate object using analogue stick around player object 1 Answer
Sidescroller, rotating via mouse control 0 Answers
How to change direction of ball whenever i rotate my camera around it? 1 Answer
Very weird rotation axis bug 1 Answer