lxFirebal69xl Posted June 23, 2016 Share Posted June 23, 2016 Hey folks, recently I ran into trouble with a camera script I'm working on, here's the code: function Script:Start() self.camerarotation=Vec3(0) self.mouseposition=Vec2(0,0) self.lookspeed=0.1 self.looksmoothing=5 self.mouseposition=Vec2() self.mousespeed=Vec2() local window = Window:GetCurrent() local cx=window:GetClientWidth()/2 local cy=window:GetClientHeight()/2 window:SetMousePosition(cx,cy) end function Script:UpdatePhysics() local window = Window:GetCurrent() local cx=window:GetClientWidth()/2 local cy=window:GetClientHeight()/2 local camerarotation = self.entity:GetRotation() local mousepos=window:GetMousePosition() window:SetMousePosition(cx,cy) self.mousespeed.x = Math:Curve(mousepos.x-cx,self.mousespeed.x,self.looksmoothing) self.mousespeed.y = Math:Curve(mousepos.y-cy,self.mousespeed.y,self.looksmoothing) camerarotation.x = Math:Min(camerarotation.x+self.mousespeed.y*self.lookspeed,30) camerarotation.x = Math:Max(camerarotation.x+self.mousespeed.y*self.lookspeed,-35) camerarotation.y = Math:Min(camerarotation.y+self.mousespeed.x*self.lookspeed, -55) camerarotation.y = Math:Max(camerarotation.y+self.mousespeed.x*self.lookspeed, -130) self.entity:SetRotation(camerarotation) end The goal is to just have a camera with the mouse's movement, and while it does work beautifully for what I'm going for, if you try it you'll see a problem which as said in the title is that the camera looks down indefinitely. How could I solve this issue? Quote Link to comment Share on other sites More sharing options...
Genebris Posted June 23, 2016 Share Posted June 23, 2016 I guess you should use http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entityturn-r29 instead of setrotation. Quote Link to comment Share on other sites More sharing options...
macklebee Posted June 24, 2016 Share Posted June 24, 2016 I have tried this and i am not experiencing the problems you are stating. For me, the camera doesn't rotate unless I move the mouse cursor. 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...
lxFirebal69xl Posted June 24, 2016 Author Share Posted June 24, 2016 I guess you should use http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entityturn-r29 instead of setrotation. Using Turn makes it so the camera spins around like a tornado. I have tried this and i am not experiencing the problems you are stating. For me, the camera doesn't rotate unless I move the mouse cursor. That is weird, did you spawn a camera and attached this script to it? Quote Link to comment Share on other sites More sharing options...
Genebris Posted June 24, 2016 Share Posted June 24, 2016 Did you just replace SetRotation with Turn? No wonder it spins like a tornado. You need to rotate by the needed difference. EDIT: Your script works fine for me too. Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted June 25, 2016 Author Share Posted June 25, 2016 Did you just replace SetRotation with Turn? No wonder it spins like a tornado. You need to rotate by the needed difference. EDIT: Your script works fine for me too. I don't get what you mean by "You need to rotate by the needed difference." How come the script is working fine for you guys but not for me... Quote Link to comment Share on other sites More sharing options...
Genebris Posted June 25, 2016 Share Posted June 25, 2016 Try it on the new project. Also, I see now that Turn is actually worse for this. Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted June 25, 2016 Author Share Posted June 25, 2016 Try it on the new project. Also, I see now that Turn is actually worse for this. Tried it on a new project, still same issue. Quote Link to comment Share on other sites More sharing options...
macklebee Posted June 25, 2016 Share Posted June 25, 2016 Tried it on a new project, still same issue. All I could suggest at this point is for you to post an actual working example of the problem so we can test for ourselves as the script you provided is not causing the issue that you are stating - at least not for me or genebris. Maybe just a simple Main.lua script with the camera script implemented in its code. Only other thing that I would have done is to use Math:Round() on the calculation on the variables 'cx' & 'cy' as this used to cause camera drifting without it in LE2 when calculating the screen center. 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...
lxFirebal69xl Posted June 25, 2016 Author Share Posted June 25, 2016 I just exported a small project where this issue is present, give it a try. https://www.dropbox.com/s/wi7t4dtedqw5ckg/derp.zip?dl=0 Quote Link to comment Share on other sites More sharing options...
macklebee Posted June 25, 2016 Share Posted June 25, 2016 I just exported a small project where this issue is present, give it a try. Works just fine for me. Other than the weird clamp you have on the camera rotations that prevent it from looking past certain angles, the camera only rotates based on mouse movement. 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...
shadmar Posted June 25, 2016 Share Posted June 25, 2016 What kind of resolution? Maybe round the window width and heigth. 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted June 25, 2016 Author Share Posted June 25, 2016 Works just fine for me. Other than the weird clamp you have on the camera rotations that prevent it from looking past certain angles, the camera only rotates based on mouse movement. The clamps are supposed to be there, but I don't get why it works well for you but not for me. What kind of resolution? Maybe round the window width and heigth. Just tried rounding the window width and height, no dice, still same problem. EDIT: Managed to fix it, switched local cx=window:GetClientWidth()/2 local cy=window:GetClientHeight()/2 To local cx=Math:Round(window:GetWidth() / 2) local cy=Math:Round(window:GetHeight() / 2) 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.