Yeah, cos(pi / 2) is 0 so any changes don't show while at that point. I have a similar change in the code I'm playing with. Basically the same thing:
Code:
local PITCH_LIMIT = PI / 2 - 0.05
local function OnUpdate(self, elapsed)
local x, y = GetCursorPosition()
local yaw = self.yaw + (x - self.x) * INCREMENT_RATIO
local pitch = self.pitch + (y - self.y) * INCREMENT_RATIO
if pitch > PITCH_LIMIT then
pitch = PITCH_LIMIT
elseif pitch < -PITCH_LIMIT then
pitch = -PITCH_LIMIT
end
self:SetOrientation(self.distance, yaw, pitch)
self.x, self.y = x, y
end
Edit: Updated initial code to reflect the changes so far.