Hello. I have been trying to make the players camera constantly face a part. It works fine like this
local cam = workspace.CurrentCamera local plr = game.Players.LocalPlayer local chr = workspace:WaitForChild(plr.Name) game:GetService("RunService").RenderStepped:connect(function() cam.CFrame = CFrame.new((chr.Head.CFrame).p, workspace.Part.Position) end)
But when I add .lookVector
like so, it completely goes haywire.
local cam = workspace.CurrentCamera local plr = game.Players.LocalPlayer local chr = workspace:WaitForChild(plr.Name) game:GetService("RunService").RenderStepped:connect(function() cam.CFrame = CFrame.new(chr.Head.CFrame.lookVector * -5, workspace.Part.Position) end)
Could anyone help?
The first 3 values of CFrame is the position, and the rest is the rotation matrix. You got it mixed up, so instead of:
local cam = workspace.CurrentCamera local plr = game.Players.LocalPlayer local chr = workspace:WaitForChild(plr.Name) game:GetService("RunService").RenderStepped:connect(function() cam.CFrame = CFrame.new(chr.Head.CFrame.lookVector * -5, workspace.Part.Position) end)
do:
local cam = workspace.CurrentCamera local plr = game.Players.LocalPlayer local chr = workspace:WaitForChild(plr.Name) game:GetService("RunService").RenderStepped:connect(function() cam.CFrame = CFrame.new(workspace.Part.Position,chr.Head.CFrame.lookVector * -5) end)
Another way of solving this is by setting the position of the camera, then the position to look at.
cam.CFrame = CFrame.new(CFrame.new(chr.Head.CFrame * CFrame.new(0,0,-5)).p, chr.Head.Position)