LookVector of Mouse?

Basically, I need to get the LookVector of a mouse. But I’m not really sure how to do this??

This is what I was trying to use

local MouseDirection = mouse;UnitRay.Direction

I get this error: UnitRay is not a valid member of Vector3

How am I supposed to get the LookVector of a Mouse?

Use this code:

local lookVector = (mouse.Hit.Position - camera.CFrame.Position).Unit

Tell me your results (the lookvector will have a magnitude of 1).

1 Like

it says "Hit is not a valid member of Vector3 "

Is mouse a Mouse object or a position?

Well I have a local script that fires the current mouse and camera,

event:FireServer(m.Hit.Position,chr,camera)

then there is a server script the gets the lookvector of the mouse.

local LookVector = (m.Hit.Position - camera.CFrame.Position).Unit -- Error: "Hit is not a valid member of Vector3"

If I just use

event:FireServer(m,chr,camera) -- local script

then it gets the error Attempt to index nil with ‘Hit’ on the ServerScript

You’re firing the position of the mouse, and then retrieving it like it’s a mouse. You can’t send that object to the server, because it doesn’t exist on the server. Instead keep the original client code, and switch the server code to this:

local LookVector = (m - camera.CFrame.Position).Unit
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.