Hi I was wondering how to get a vector3 value denoting the world coordinates that the camera is currently facing on the client using the camera’s CFrame
Coordinates typically describe locations in space. So you want the point that the camera is facing? That doesn’t really make much sense, since facing means which direction something is pointing. It’s more common to describe directions with vectors. Which makes things super confusing, because in Roblox (and lots of other game frameworks/engines), there’s a data type called Vector3
which is used in both cases (coordinates and directions).
I’m guessing what you really want is the direction that the camera is facing? In that case, CFrame
values have a property called LookVector
, which is just what you’re looking for. So if you have a Part
called “Part” with a script in it, you can get the direction that the Part
is facing like so:
local part = script.Parent
local partFacingDirection = part.CFrame.LookVector
You can read more about the properties and methods of the CFrame
data type here. I recommend looking at RightVector
and UpVector
, or just giving the whole page a read.
For anyone who wants to know I used rays to solve the problem by positioning a ray at the camera’s position and pointed the ray to face the opposite direction of the camera’s look vector and then I used a loop to find all parts touching the ray and checked if the touching part was the target part and then I snapped the part into the ray hit position.