Jump to content

Camera script making the camera go down indefinitely.


lxFirebal69xl
 Share

Recommended Posts

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?

Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

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

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.

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

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)

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...