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

How would I make a smoother top-down 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)

1 answer

Log in to vote
0
Answered by
anerth 25
9 years ago

The only way I can think of is having the player (Noob) as an end position for a BodyPosition and the place you spawn for a start position (look at video 2 at this link: http://blog.roblox.com/2014/12/watch-the-complete-roblox-hour-of-code-tutorial-series )

Ad

Answer this question