- Home /
What other methods are there for locking rotation of an object?
I have an object that is the pivot point for a camera, so when the player presses a joystick, the camera should rotate around the point only on the x and the y axis. Every time I try editing this rotation, it causes a rotation on the z axis as well, but I need that to stay at a 0 rotation. I have tried adding a rigid body and locking it within the constraints, and I have tried hardcoding it in to the update function, but for some reason, it still wants to cause rotation on the z axis. Any help would be greatly appreciated.
Is this an issue of what angles are expressed in the Inspector or are you seeing real physical rotation on the 'z' axis?
Actual rotation on the 'z' axis. I was, however, able to get this cleaned up a little bit, by un-parenting the camera. I learned that using C# and the Transform.Rotate function (due to the fact that I can't use transform.rotation.eulerangles.x += rotationamount) that the pivot is a local point that is between the parent and child of the game object. So now I have it set up as unparented from the pivot point, and then just rotates around that, but it's still trying to rotate around the 'z' axis as well.
Without seeing the code and maybe a project, I don't know what is going on. But you have to be careful about how you interpret rotations in the inspector. Rotations are stored in Quaternions. Euler angles are derived out of the Quaternion, and the angle put in is not the angle back out. So for example, if you execute this code:
transform.eulerAngles = Vector3(180,0,0);
Debug.Log(transform.eulerAngles);
...you will see the output is (0,180,180). That is the same physical rotation, but represented differently. You code might have only rotated around the 'x' axes, but the Inspector will show a 'Z' rotation.
Hmm, I guess that's very possible, because I was unaware that it would rotate it on the z axis from that code. I was using the Transform.Rotate feature that is built into Unity Code. I guess I'll have to play with the numbers a bit more, but for what I'm doing right now to just build a demo, the RotateAround $$anonymous$$ethod that I described above is working well enough.
Your answer
Follow this Question
Related Questions
Problem with Camera rotating 0 Answers
How to Math.f Clamp this 0 Answers
How do I make this Camera movement happen when I right click? 1 Answer
how can stop camera wrong spinning? 0 Answers
third person camera 2 Answers