Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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?

0
if there's a way that works fine, why dont you use it? loulou1112 35 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

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)
0
sorry but that didnt work. The way this CFrame.new works is CFrame.new(Vector3 pos, Vector3 lookAt) connor12260311 383 — 7y
0
This is what you're looking for then: cam.CFrame = CFrame.new(chr.Head.Position,workspace.Part.Position) User#14829 0 — 7y
Ad
Log in to vote
0
Answered by
Xiousa 156
7 years ago

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)

Answer this question