Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Have a part track where the player is looking?

Asked by
hudzell 238 Moderation Voter
9 years ago

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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

0
I worked, thanks a lot! hudzell 238 — 9y
Ad

Answer this question