Make part face where the camera is looking

How do I make my part face where my camera is facing???
I tried using

CFrame.new(part.Position,camera.Position)

Didnt work
and

CFrame.new(part.Position,camera.CFrame.LookVector) --I tried Multiplying the lookvector with different numbers but still doesnt work

You can get the camera’s CFrame’s orientation, assuming you already have the camera’s CFrame:

local camOrientation = camCFrame-camCFrame.Position;

You can then apply that orientation to the part:

part.CFrame = CFrame.new(part.Position)*camOrientation;
2 Likes

Part.CFrame = Camera.CFrame or Part.CFrame = CFrame.new(Part.Position,Part.Position+Camera.CFrame.LookVector) if you want the part to be not on the camera

This is now deprecated:

You should use this:

function lookAt(target, eye)
    local forwardVector = (eye - target).Unit
    local upVector = Vector3.new(0, 1, 0)
    -- You have to remember the right hand rule or google search to get this right
    local rightVector = forwardVector:Cross(upVector)
    local upVector2 = rightVector:Cross(forwardVector)
 
    return CFrame.fromMatrix(eye, rightVector, upVector2)
end
6 Likes