Ad
Log in to vote
0

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

Asked by 7 months 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 33 — 7mo

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

2 answers

Log in to vote
0
Answered by 7 months 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 363 — 7mo
0
This is what you're looking for then: cam.CFrame = CFrame.new(chr.Head.Position,workspace.Part.Position) killerbot29003 116 — 7mo
Ad
Log in to vote
0
Answered by
Firefaul 129
7 months 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



Ad