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?
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.