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

Less Laggy Pathfinding?

Asked by 9 years ago

I'm making a survival game similar to the Call of Duty Zombies game mode, and therefor am using the pathfinding service to have the monsters find their way to the player through the map. This works perfectly with one exception, the bigger the area and the more monsters, the more lag that is created. The map itself is only about 400 by 400 studs big, and there can only be a max of 24 monsters on the map at a time. After around 8 monsters the lag is already noticeable, with the weapon animations taking significantly longer to happen, and registering shots is horribly slow. with 24 monsters and a fully unlocked map, it's might as well be a slide show. Here's the thing though, it doesn't mess with the frame-rate. The program seems to load fine, but it's like Studio isn't letting the game have the resources it needs in order to run the game more smoothly at the cost of frame rate.

So here's my main question, is the game lagging only because i'm running in Play Solo mode and therefor the client is handling all of the calculations? If not, then would there be a way to distribute the pathfinding between all of the monsters, or just have a way so it doesn't lag as much?

Here's the part of the script that the monsters use to pathfind:

while true do
    wait(.1)
    target = FindNearestTorso() -- common function
    if target ~= nil then
        path = game:GetService("PathfindingService"):ComputeSmoothPathAsync(relative.Position, target.Position, 500)
        point = path:GetPointCoordinates()[2] -- if I choose 1, the just stay in place
        if point ~= nil then
            part = Instance.new("Part")
            part.Parent = game.Workspace
            part.Transparency = 1
            part.FormFactor = Enum.FormFactor.Custom
            part.Size = Vector3.new(1,1,1)
            part.Position = point
            part.Anchored = true
            part.CanCollide = false
            local sc = script.Bye:Clone()
            sc.Parent = part
            sc.Disabled = false
            script.Parent.Humanoid:MoveTo(part.Position, part)
        else
            script.Parent.Humanoid:MoveTo(target.Position, target) -- sometimes the point will be nil, and if this code isn't here the monster stops moving indefinitely
        end
    end
end

I really appreciate any feedback if possible! Thank you! :)

0
Is there one of these scripts in every monster? parkderp1 105 — 9y
0
I just tried it on mine. 17 copies and it's just fine. But can we get a look at the whole script. Maybe it isn't just that one part. Scubadoo2 115 — 9y

Answer this question