Maaco Posted December 12, 2018 Share Posted December 12, 2018 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 1 Quote Link to comment Share on other sites More sharing options...
Maaco Posted December 13, 2018 Author Share Posted December 13, 2018 This is quitte a showstopper for this project? I'm beginning to suspect it's a bug... Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted December 13, 2018 Share Posted December 13, 2018 Without an example of your code its hard to guess what is wrong with your project. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted December 13, 2018 Share Posted December 13, 2018 As Thirsty Panther said... but it might have to do with gimbal lock. Don't know why but Leadwerks doesn't handle this for you. Quote Link to comment Share on other sites More sharing options...
Maaco Posted December 13, 2018 Author Share Posted December 13, 2018 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 Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted December 14, 2018 Solution Share Posted December 14, 2018 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 Quote 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 More sharing options...
Maaco Posted December 14, 2018 Author Share Posted December 14, 2018 Thanks Josh: using SetMatrix instead of SetRotation/SetPosition indeed solved the problem! 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.