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

Camera Script Orientation Not Facing Head Problem?

Asked by 4 years ago

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

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
4 years ago

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

Ad

Answer this question