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

camera script glitchy?

Asked by
theCJarmy7 1293 Moderation Voter
8 years ago
player = game.Players.LocalPlayer
char = player.Character
cam = game.Workspace.CurrentCamera

local part = Instance.new("Part")
part.Transparency = 1
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(30,20,30)
cam.CameraSubject = part
wait(1) -- so that i have time to fall from the sky onto the baseplate
while wait() do
        local h = char.Torso.Position
        part.Position = Vector3.new(h.X,20,h.Z)
    end

the script above makes a part above my head, end puts the camera in it. the only problem is that if i set my walkspeed high enough, the camera will be really jumpy trying to be at the position. i tried using.Changed, but for some reason, it never works for me. how do i have the parts position not be jumpy at high speeds?

1 answer

Log in to vote
1
Answered by 8 years ago

You'll need the part to change position each time that the screen updates. You can use RunService's BindToRenderStep function to do this.

player = game.Players.LocalPlayer
char = player.Character
cam = game.Workspace.CurrentCamera

local part = Instance.new("Part")
part.Transparency = 1
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(30,20,30)
cam.CameraSubject = part
wait(1) -- so that i have time to fall from the sky onto the baseplate
-- "move part" : The name of the bind, can be used with UnbindFromRenderStep to stop the function
-- 2000 : The priority, higher values run after smaller values. 2000 should make it run last
game:GetService("RunService"):BindToRenderStep("move part", 2000, function()
     local h = char.Torso.Position
     part.Position = Vector3.new(h.X,20,h.Z)
end)
0
i set the 2000 to 20, and it worked! I've never heard about this function before, thank you. theCJarmy7 1293 — 8y
Ad

Answer this question