Jump to content

Camera Pitch Rotation problem


Maaco
 Share

Go to solution Solved by Josh,

Recommended Posts

I'm working on a controller system for a small 'spacecraft' that has two flightmodes: a 'hover' mode that works fine (steering somewhat like a drone) and a 'normal'  flightmode that allows you to rotate around pitch, yaw and bank axis. That works ok too, but when I make a looping (rotating around the pitch axis) the camera seems to get 'left behind' when passing a certain amount of pitch (90 degrees up or down).

Here's a link with a video of the issue, it'll show at 0:26 (and at 0:33 again) when pitching nose down:

 The ship (a Rigid Body with Prop physics wiht a mass of 30) is controlled by applying AddForce and AddTorque. I noted that it also happens when colliding with scenery objects.

Any suggestions on what is causing this?

Thanks,

Maaco

  • Like 1
Link to comment
Share on other sites

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
 

 

Link to comment
Share on other sites

  • Solution

The problem is that the Euler rotation returned by GetRotation in your UpdateCamera function is ambiguous. Try SetMatrix to replace SetRotation and SetPosition.

--Adjust the camera orientation relative to entity
function Script:UpdateCamera()
    self.camera:SetMatrix(self.entity:GetMatrix(true),true)
    self.camera:Move(0,1,0)
end

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...