- Home /
Rigidbody wont rotate in the other direction.
Basically, my player would rotate correctly, all normal, until I hit it to a wall (usually need to be done multiple times) and it'd rotate in a strange way. I rotate my object incrementally, only a small number (~10 deg) for each FixedUpdate(). Rotation in the same axis (Y-axis) is going to be different if you do it CW vs CCW, one of them is going to get faster by almost x2, and the other is going to be way slower at x10 (which side is faster/slower is random).
I figured it's because I'm incrementing eulerAngles, which isn't advised in the doc. Then I changed into relative rotation such as * quat operations, Rotate(), MoveRotation(), etc, alas the problem persisted. You can check my comments to see what I've tried, all not working.
// Rotation gradual - Relative target
// Delta = right(taget) - left(current)
rot = transform.eulerAngles;
rot.y = AngleOffset(rot.y, 0f);
Debug.Log("--- " + rot.y);
float delta = Mathf.DeltaAngle(rot.y, angle);
isCW = delta > 0f ? 1f : -1f;
drot.y = isCW * rotate * Time.deltaTime;
rot.y = AngleOffset(rot.y, 0f);
delta = Mathf.DeltaAngle(AngleOffset(rot.y, drot.y), angle);
if (delta * isCW < 0f) drot.y = 0; // Check if changed polarity
Debug.Log(drot.y);
// Add the drot to current rotation
rigidBody.rotation *= Quaternion.AngleAxis(drot.y, transform.up);
//transform.rotation *= Quaternion.AngleAxis(drot.y, Vector3.up);
//transform.Rotate(drot, Space.Self);
//rigidBody.AddTorque(drot);
//rigidBody.MoveRotation(rigidBody.rotation * Quaternion.Euler(drot));
Debug.Log(rot);
As you can see, while the eulerAngles is still there, it isn't directly used. And everything that use it would return correct number on Debug.Log. The problem entirely happens on the last part.