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

PathFindingService not finding the best path? {SOLVED}

Asked by 3 years ago
Edited 3 years ago

I have been fiddling around with path finding service and have come up with this for an obby bot:

local Model = game.Workspace.Waypoints
local Start = game.Workspace.Obby.Start
local Finish = game.Workspace.Obby.Finish
local human = script.Parent.Humanoid

local pfs = game:GetService("PathfindingService")

local path = pfs:CreatePath({AgentRadius = 1, AgentHeight = 7, AgentCanJump = true})



local function WayPointsCreate(pathCreated)
    local Waypoints = pathCreated:GetWaypoints()
    if path.Blocked then
        path:ComputeAsync(Start.Position, Finish.Position)
    end
    for _, WayPoint in pairs(Waypoints) do
    local PathPoint = Instance.new("Part")
    PathPoint.Shape = Enum.PartType.Ball
    PathPoint.Parent = Model
    PathPoint.Material = Enum.Material.Neon
    PathPoint.Size = Vector3.new(0.5,0.5,0.5)
    PathPoint.Position = WayPoint.Position
    PathPoint.CanCollide = false
    PathPoint.Anchored = true

    end
    return(Waypoints)
end

local function Move(pathCreated)

    local Waypoints = WayPointsCreate(pathCreated)

    for _, waypoint in pairs(Waypoints) do
        if path.Blocked then
            path:ComputeAsync(Start.Position, Finish.Position)
        end
        if waypoint.Action == Enum.PathWaypointAction.Jump then
            human.Jump = true                   
        end
        human:MoveTo(waypoint.Position)
        human.MoveToFinished:Wait(1)
    end
end

local function Reset()
    for _, point in pairs(game.Workspace.Waypoints:GetChildren()) do
        point:Destroy()
    end
end

while true do
    Reset()
    path:ComputeAsync(Start.Position, Finish.Position)
    if path.Blocked then
        path:ComputeAsync(Start.Position, Finish.Position)
    end
WayPointsCreate(path)
Move(path)
human:MoveTo(Finish.Position)

    Reset()

local path2 = pfs:CreatePath()

path2:ComputeAsync(Finish.Position, Start.Position)
WayPointsCreate(path2)
Move(path2)
    human:MoveTo(Finish.Position)
    end

But as you can see in this video: https://www.youtube.com/watch?v=XTsGBGDcA-Q

I beat the bot and it had a walkspeed of 30 I had obviously found a better path but I beleive it is something to do with the jumps as if you get rid of the path that connects the bot will just walk off the edge.

Any tips for better performance?

0
(File > Studio Settings > Studio > Visualization > Show Navigation Mesh) you can use this to see where an NPC would jump. MarkedTomato 810 — 3y
0
Thanks this helps a lot :) terraria265 5 — 3y

Answer this question