Jump to content

Mouse look when camera is fixed


Borov

Recommended Posts

So I'm trying to track the mouse movement when the camera is fixed for a player, during each frame (the event onClientRender). I tried the function getWorldFromScreenPosition, but apparently it only gives you the world position as looking out from the camera, so it doesn't change when the camera is fixed. I don't think there's a way to get the mouse x axis or y axis movement either. Can you guys think of another way to track mouse movement?

btw, it seems like setCameraLookAt doesn't work at all... I set it even to 0,0,0 it still doesn't change anything (I did use a timer for it, 60msec)

Link to comment

Im actually trying the same with good results. I already managed to move the camera up and down over 180° along the y mouse axis and about 360° to the right and left using the mouse x axis. I wrote a little "setCameraRotation" function on my own that calculates a point on the surface of a sphere around the current camera position using 2 angles.

Here's the code:

function setCameraRotation (rotx, rotz) 
    local x, y, z = getCameraPosition () 
    local x2 = math.sin (math.rad(rotx))*math.cos (math.rad(rotz)) 
    local y2 = math.sin (math.rad(rotx))*math.sin (math.rad(rotz)) 
    local z2 = math.cos (math.rad(rotx)) 
    local result = setCameraLookAt (x+x2, y+y2, z+z2) 
    --outputChatBox (tostring (x+x2*3).." "..tostring (y+y2*3).." "..tostring(z+z2*3)) 
    --outputChatBox (tostring (rotx).." "..tostring (rotz)) 
    return result 
end 

Now i only got problems with saving the current rotation when mouse1 is released so i can start at the same camera look when i press mouse1 again but when i tried to add the rotation to the last rotation the camera moves totally weird...

Btw i used the onClientCursorMove Event to controle the camera. It's much easier =)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...