Hey all,
I can’t seem to get freezing rotation to work. I have a sphere with a rigidbody on it, and I have pressed the ‘freeze rotation - z’ checkbox on it.
I want the sphere to be able to rotate in y for changing direction (I rotate it around the global up axis) and rotate along its own x (around axis transform.right) to roll forward. I don’t want it to rotate along z, because then the transform.right axis moves and rolling forward no longer works properly.
However, when I run my script, it seems like rotation along z is still happening without any change. Can anyone help me figure out why? Here is my control code:
void FixedUpdate () {
//SPHERE MOVEMENT
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
//turning
if (Mathf.Abs(hor) > deadZone) {
rigidbody.AddTorque (Vector3.up * hor);
}
//forward
if (Mathf.Abs(ver) > deadZone) {
//add torque around right-hand axis
rigidbody.AddTorque(transform.right.normalized * ver);
}