Ah yes gimbal lock...I didn't think of that.
I've simplified/extracted part of the code (to clarify) that seems to cause the issue.
When I attach this simple script to an entity it shows the same behavior/issue when exceeding +90 or -90 degrees of rotation around the X-Axis:
function Script:Start()
self.entity:SetGravityMode(false)
-- Create a camera
self.camera = Camera:Create()
end
--Adjust the camera orientation relative to entity
function Script:UpdateCamera()
self.camera:SetRotation(self.entity:GetRotation())
self.camera:SetPosition(self.entity:GetPosition())
self.camera:Move(0,1,0)
end
function Script:UpdatePhysics()
--Get the game window
local window = Window:GetCurrent()
--Keyboard input
if window:KeyDown(Key.W) then self.entity:AddTorque(130,0,0,false) end
if window:KeyDown(Key.A) then self.entity:AddTorque(0,-130,0,false) end
if window:KeyDown(Key.D) then self.entity:AddTorque(0,130,0,false) end
if window:KeyDown(Key.S) then self.entity:AddTorque(-130,0,0,false) end
if window:KeyDown(Key.Q) then self.entity:AddForce(0,15,0,false) end
if window:KeyDown(Key.E) then self.entity:AddForce(0, 0, 50,false) end
if window:KeyDown(Key.Z) then self.entity:AddTorque(0, 0, 100,false) end
if window:KeyDown(Key.C) then self.entity:AddTorque(0, 0, -100,false) end
end
function Script:UpdateWorld()
--Update the camera each frame
self:UpdateCamera()
end