Camera Movement Clamping

I have some general theory questions regarding camera movement that I was hoping someone might be able to offer some insight to.

I am interested in clamping my camera movement so that the rotation around the player can’t get too high or too low. I noticed that the rotation on the camera shows between -1 and 1 when I print it while the game is playing, but in scene view it appears to be in degrees related to either world or local space, whichever I am using. Is the -1 and 1 related to Euler angles? If so, is there a way to easily convert that back to degrees so I can know where I want the clamping to happen? I can learn Euler angles if I have to, but… eww.

Also I noticed that even that -1 and 1 position seems to be different at times even when the camera appears to be in the same position. For example, some times when the camera appears to be about about 30 degrees relative to the ground plane the rotation of the camera will return .23~ and sometimes it returns .65~. This was rotation around the x axis when y is the up direction.

Maybe there’s a book or some reference material out there that does a good job of explaining the way everything relates to each other in 3d space in Unity.

Hi Zafaron,

Euler angles are not the problem. You probably learnt about them in school. Unity works internally with quaterions, though. For this reason, you should not rely too much on the output in Euler angles because there could be conversion problems.

A simple solution could be to use Transform.LookAt: The camera always looks at the player. Then you could simply clamp the movement of the camera on the y-axis. The rotation/radius can be restricted with Vector3.Distance.

If you want to learn about quaterions, I can recommend this video by numberphile:

That video did a really good job of explaining quaternions, thanks Nina.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms