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

Camera Script Orientation Not Facing Head Problem?

Hi, I'm writing a third person game and I have a smooth third person camera but it doesn't follow the orentation of the head? Is there anyway to do this?

Script:

repeat wait() until game.Players.LocalPlayer.Character

-- Settings
local XCamOffSet = 5
local YCamOffSet = 2
local ZCamOffSet = 0

local Player = game.Players.LocalPlayer
local Character = game.Players.LocalPlayer.Character

local RunService = game:GetService("RunService")
local Camera = game.Workspace.CurrentCamera

local FakeCamera = nil

function runCamera()
	FakeCamera = Instance.new("Part",Camera)
	FakeCamera.CanCollide = false
	FakeCamera.Anchored = true
	
	while wait() do
		local m = CFrame.new(Character.Head.Position) * CFrame.new(XCamOffSet, YCamOffSet, ZCamOffSet)
		
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera:Interpolate(m, CFrame.new(Character.Head.Position), 0.1)
	end
end

runCamera()

1 answer

✓ Accepted answer

When you were feeding the CFrame for both computing m and interpolating, you were creating a new cframe from the position of the head. You want to keep the orientation that the cframe provides. I also used the humanoidrootpart's cframe instead because the head's would have unnecessary movement due to animations.

repeat wait() until game.Players.LocalPlayer.Character

-- Settings
local XCamOffSet = 5
local YCamOffSet = 2
local ZCamOffSet = 10

local Player = game.Players.LocalPlayer
local Character = game.Players.LocalPlayer.Character

local RunService = game:GetService("RunService")
local Camera = game.Workspace.CurrentCamera

local FakeCamera = nil

function runCamera()
    FakeCamera = Instance.new("Part",Camera)
    FakeCamera.CanCollide = false
    FakeCamera.Anchored = true

    while wait() do
        local m = Character.HumanoidRootPart.CFrame * CFrame.new(XCamOffSet, YCamOffSet, ZCamOffSet)

        Camera.CameraType = Enum.CameraType.Scriptable
        Camera:Interpolate(m, m+Character.HumanoidRootPart.CFrame.lookVector, 0.1)
    end
end

runCamera()

I also changed ZCamOffSet to 10 since I couldnt see the player :p

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