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

How would I make a better 3rd person overview camera script?

Asked by 9 years ago

I have a top-down view script that tracks a character called "Noob" when he moves that is called by the MoveCharacter RemoteFunction. The camera will follow but it looks all cutty and glitchy. I have seen multiple top-down games (including Dungeon Delver and Guest Quest) that have a very smooth view. I was wondering how you would do this?

This is my current attempt:

wait(1)

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
plr.Character:remove()
local camera = game.Workspace.CurrentCamera
local char = game.Workspace:WaitForChild("Noob")
local head = char.Head
local humanoid = char.Humanoid
local offset = {}
offset.x = 10
offset.y = 30
offset.z = 10

--plr.CameraMaxZoomDistance = 100
--plr.CameraMinZoomDistance = 80

Focus = function(pos, duration)
    for i = 1, 10 do
        local cf = CFrame.new(Vector3.new(
            pos.x + offset.x,
            pos.y + offset.y,
            pos.z + offset.z)
        , pos)

        camera:Interpolate(cf, CFrame.new(Vector3.new(pos.x, pos.y, pos.z)), duration)
    end
end

local pos = head.Position
camera.CameraType = "Scriptable"
camera.CoordinateFrame = CFrame.new(Vector3.new(pos.x + offset.x, pos.y + offset.y, pos.z + offset.z), pos)


game.Workspace.MoveCharacter.OnClientEvent:connect(function(pos)
    Focus(pos, ((head.Position - pos).magnitude) / humanoid.WalkSpeed) --The interpolation time is basically the distance it is away divided by the studs per second the character walks so that the animation will complete by the time the character gets there
end)

Answer this question