SlipperyBrick Posted September 15, 2016 Share Posted September 15, 2016 I have a custom character controller script and I want to clamp the Y axis for my character controller. Right now I can move my mouse down on the Y axis and the camera will let me go completely around on the Y axis, I need to clamp the camera movement to a certain angle. --[[ ***LEADWERKS MEASUREMENTS*** Corridor Width = 256cm Wall Height (Standard) = 320cm Wall Height (Lowest) = 288cm Doorway Width = 128cm Doorway Height = 256cm Wall Thickness (Doorways) = 32cm ]]-- function Script:Start() local window = Window:GetCurrent() --self.camera = players camera --self.entity = temporary box to use for player movement --creates a camera in the scene and parents to the entity self.camera = Camera:Create(self.entity) --sets the type of the object to player self.entity:SetKeyValue("type", "player") local mass = self.entity:GetMass() if self.entity:GetMass() == 0 then Debug:Error("Player mass should be greater than 0.") end --gets the entity position local entpos = self.entity:GetPosition(true) --sets the camera height self.camera:SetPosition(entpos.x, entpos.y + 1.9, entpos.z, true) --sets the camera rotation variable self.camrotation = self.entity:GetRotation(true) self.camera:SetRotation(self.camrotation.x, self.camrotation.y, 0, true) mousex = Math:Round(window:GetWidth()/2) mousey = Math:Round(window:GetHeight()/2) --sets the camera post processing effects self.camera:SetFOV(70) self.camera:AddPostEffect("Shaders/PostEffects/ssao.lua") self.camera:SetMultisampleMode(4) end function Script:UpdateWorld() local window = Window:GetCurrent() --gets the position of the mouse local mouseposition = window:GetMousePosition() window:SetMousePosition(mousex, mousey) local dx = mouseposition.x - mousex local dy = mouseposition.y - mousey self.camrotation.x = self.camrotation.x + dy / 10 self.camrotation.y = self.camrotation.y + dx / 10 self.camera:SetRotation(self.camrotation.x, self.camrotation.y, 0, true) end function Script:UpdatePhysics() local window = Window:GetCurrent() --xmove = left/right speed --zmove = forward/backwards speed local xmove = 0 local zmove = 0 --key bindings for movement if window:KeyDown(Key.W) then zmove = 1 end if window:KeyDown(Key.S) then zmove = -1 end if window:KeyDown(Key.A) then xmove = -1 end if window:KeyDown(Key.D) then xmove = 1 end self.entity:SetInput(self.camera:GetRotation(true).y, zmove, xmove) end Here is the script at the moment. Any help is appreciated. Quote Link to comment Share on other sites More sharing options...
macklebee Posted September 15, 2016 Share Posted September 15, 2016 I think you mean clamp the rotation around the X-axis. http://www.leadwerks.com/werkspace/topic/14389-headbobbing-mechanic/#entry98643 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SlipperyBrick Posted September 16, 2016 Author Share Posted September 16, 2016 Ah perfect, thanks macklebee! Is there a way to stop it from getting all jittery? When I drag my mouse down it hits the value I've put for the clamp but if I continue to drag down the screen goes all jittery, like it's fighting against my mouse to not go past the value I've put in to clamp the camera. Quote Link to comment Share on other sites More sharing options...
macklebee Posted September 16, 2016 Share Posted September 16, 2016 I don't ever remember having that issue. If you run my example shown do you have the same issue? If not, then i would suggest you set your code like my example - most noticeable difference is i set the mouse's position after setting the camera's rotation, not right after getting the mouse's position. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
SlipperyBrick Posted September 16, 2016 Author Share Posted September 16, 2016 All fixed. I was setting my camera rotation for X axis after the clamping 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.