Make an object match player camera rotation

I am making a drone object that allows the player to freecam. I want the drone to match the player’s camera rotation. How would I go about this? I only want the drone to rotate on the Y axis, but thats basically done for me anyway because of the Orbital camera type

function movePlayerCamera()
	local currentCam = workspace.CurrentCamera
	currentCam.CameraType = "Orbital"
	local currentDrone = script.Parent.Drone:WaitForChild("Cloned")
	workspace.CurrentCamera.CameraSubject = currentDrone.DroneRoot.Cam
	UIS.MouseIconEnabled = false
	localPlayer.CameraMaxZoomDistance = 0
	localPlayer.CameraMinZoomDistance = 0
end

function resetPlayerCamera()
	local hum = localPlayer.Character:FindFirstChildOfClass("Humanoid")
	if hum then
		workspace.CurrentCamera.CameraType = "Custom"
		workspace.CurrentCamera.CameraSubject = hum
		UIS.MouseIconEnabled = true
		localPlayer.CameraMaxZoomDistance = 128
		localPlayer.CameraMinZoomDistance = 0.5
	end
end


script.Parent.DroneStatus.Changed:Connect(function()
	if script.Parent.DroneStatus.Value == true then
		wait(.1)
		movePlayerCamera()
		local camCF = workspace.CurrentCamera.CFrame
		local camCFRot = camCF - camCF.Position
		local dronePos = script.Parent.Drone.Cloned.DroneRoot:GetPivot().Position

		script.Parent.Drone.Cloned.DroneRoot:PivotTo(CFrame.new(dronePos) * camCFRot)
--		Sink()
	end
	if script.Parent.DroneStatus.Value == false    then
		wait(.1)
		resetPlayerCamera()
--		UnSink()
	end
end)

You can easilly do it by just doing this

Object.CFrame = CFrame.lookAt(Object.Position,Object.Position + Camera.CFrame.LookVector)

This will match their look vectors

2 Likes