Limiting Camera Angles Using Quaternions

I’m creating my first 3D game and my math skills are limited.

I want to limit camera angles for rotations around X axis. I want it to behave like in most FPS games: it should not be possible to lean backwards or to look “between your legs”. I had some problems expressing this using Euler angles. My idea for quaternions: create two of them, one for “down” look and one for “up” look. I could then interpolate using slerp/lerp from current rotations to extreme rotations. This would allow me mapping vertical shift onto range <-1,1>, where -1 would be down while +1 would be up while 0 would be forward. Is there a better method?

I solved it with Euler angles. Damn, I’m such a 3D noob…

1 Like

Whatever gets the job done friend. Nobody who plays the game will know it’s euler instead of quaternions as long it works and the players like it! :wink: