CFrame.lookAt() account for orientation?

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All,false)

repeat task.wait()until workspace.Events:FindFirstChild("BeginAnimation").Value==true

local character=game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local head=character:WaitForChild("Head")

workspace.CurrentCamera.CameraType=Enum.CameraType.Scriptable
workspace.CurrentCamera.CameraSubject=nil;

workspace.CurrentCamera.FieldOfView=70
repeat task.wait()
    workspace.CurrentCamera.CFrame=    CFrame.lookAt(head.Position+Vector3.new(
        5,0.0
        ), Vector3.zero)*CFrame.fromOrientation(
        character.HumanoidRootPart.CFrame.Rotation.X,
        character.HumanoidRootPart.CFrame.Rotation.Y,
        character.HumanoidRootPart.CFrame.Rotation.Z
    );
until false

How do I make CFrame.lookAt() face directly at the head instead of just looking at its position?

1 Like

Sometimes you have to offset the orientation parameter of the C frame just to account for the fact that it’s not always going to point directly at it

I thought there was just X, Y, Z. Theres another?

No no you’re right all you’re doing is modifying the XY and z to account for the inaccuracy of look at, more than likely you’re offsetting the rotation on a single axis

How can I solve this? I’m getting sturdy.

I think I get what you’re trying to ask now you don’t want it to just rotate on the z-axis to face towards the head but if the head were to travel up or down you want it to also use X and Y and perfectly aim it as if you were trying to point a laser beam at it

I mean I just want to have the camera look directly at the head

Lookat should work, make sure you use the Vector3 for the origin of the camera first, then use the Vector3 for the position to look at!

Try this:

--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

--//Variables
local LocalPlayer = Players.LocalPlayer
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local CurrentCamera = workspace.CurrentCamera

--//Initialization
CurrentCamera.FieldOfView = 70

--//Functions
RunService.RenderStepped:Connect(function()
	CurrentCamera.CFrame = CFrame.lookAt(CurrentCamera.CFrame.Position, head.Position)
end)

Just edited because I realized I forgot to add something.

i already used lookat() and it does not orbit. its meant to orbit the players head while constantly looking at it

Try it now. I just edited it. It works fine for me.

that doesnt look at the players face though, it looks at the back of his head

Try this:

--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

--//Variables
local LocalPlayer = Players.LocalPlayer
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local CurrentCamera = workspace.CurrentCamera

--//Initialization
CurrentCamera.FieldOfView = 70

--//Functions
RunService.RenderStepped:Connect(function()
	CurrentCamera.CFrame = head.CFrame + head.CFrame.LookVector * 6 + Vector3.yAxis
	CurrentCamera.CFrame = CFrame.lookAt(CurrentCamera.CFrame.Position, head.Position)
end)
1 Like