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

How do you move a part relative to the camera?

Like the part is rotated in the same direction as the camera, and it moves away from it in the direction it is looking

1 comment

0

I do believe further explanation is required.

1 answer

You could position your part according to the Camera's CFrame property. A CFrame is value which represents a point and rotation in 3D space. The Camera's CFrame thus represents the position and rotation of the camera (not to be confused with its Camera.Focus property which represents the point the camera is looking at. Unfortunately, this CFrame is not rotated along with the camera, so we cannot use it to have the part face it).

You can retrieve the camera through the game.Workspace's CurrentCamera property but only in a localscript, since the camera is different for every player and for this same reason does not need to be replicated to the server.

E.g:

local camera = game.Workspace.CurrentCamera

local part = game.Workspace:FindFirstChild("Part")


while true do
	--[[
		'Multiplying' two CFrames together is like transforming the second
		CFrame from Object coordinates, coordinates relative to a point,
		to World coordinates -- absolute coordinates, i.e: coordinates
		relative to the Workspace's origin (0,0,0).
	]]--
	
	part.CFrame = camera.CFrame * CFrame.new(Vector3.new(0, 0, -10))
	-- Here we set the part's position to be ten studs away from the camera's
	-- position. 
	
	wait(0.01)
end


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