Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Have a part track where the player is looking?

I'm trying to make a 3D Screen infront of the player's camera, but I can't figure out how to move the brick a stud or two out relative to the camera's lookvector. I'm basically trying to make a 3D ScreenGui , but it's actually there in 3D space and not just on the player's screen. Help?

1 answer

✓ Accepted answer

From a LocalScript, you can get a reference to the CurrentCamera:

local cam = workspace.CurrentCamera

The cam has a .CoordinateFrame property which is the CFrame it's at:

local cframe = cam.CoordinateFrame

Since you want to maintain the same orientation and all other details, it's probably easier to give a part the same CFrame, but a few studs forward:

myPart.CFrame = cframe:toWorldSpace( CFrame.new(0, 0, -5) )
-- 5 studs forward

-- or equivalently
myPart.CFrame = cframe * CFrame.new(0, 0, -5)

You would want to do this while waiting with the .RenderStepped event of RunService so that it is always exactly in the correct location and doesn't lag behind when the camera moves.

1 comment

0

I worked, thanks a lot!

This discussion is preserved as it was. New answers, comments, and votes are closed.