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

I'm having trouble manipulting the camera with lookVector. [?]

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?

1 comment

0

if there's a way that works fine, why dont you use it?

2 answers

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)

2 comments

0

sorry but that didnt work. The way this CFrame.new works is CFrame.new(Vector3 pos, Vector3 lookAt)

0

This is what you're looking for then: cam.CFrame = CFrame.new(chr.Head.Position,workspace.Part.Position)

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)

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