#How do I fix this pathfinding bug?

1 messages · Page 1 of 1 (latest)

plush void
#

I'm kinda new to pathfinding and am trying to make an npc that when an event is triggered it goes to nearest "survivor" player. the pathfinding works but it tries to go over ledges that it shouldn't be able to. Is there a way to make the path find not try to go up ledges?

I will reply with the script as otherwise i hit character limit 🙁

#

Script: local PS = game:GetService("PathfindingService")
local teams = game:GetService("Teams")
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local Remotes = RS.Remotes
local char = script.Parent

local billy = script.Parent
local hum = billy.Humanoid
local hrp = billy.HumanoidRootPart

local path = PS:CreatePath({

AgentCanJump = false,
AgentCanClimb = true,

})

local maxDistance = 10000

local Event = Remotes.StartPathfind

Event.OnServerEvent:Connect(function()
local nearestPlayer, nearestDistance
for _, player in pairs(Players:GetPlayers()) do
if player.Team == "Killers" then
return
end
local character = player.Character
local distance = player:DistanceFromCharacter(billy.HumanoidRootPart.Position)
if not character or
distance > maxDistance or
(nearestDistance and distance >= nearestDistance)
then
continue
end
nearestDistance = distance
nearestPlayer = player
end
print("The nearest player is ", nearestPlayer)

local Target = nearestPlayer

path:ComputeAsync(hrp.Position, Target.Character.HumanoidRootPart.Position)

if path.Status == Enum.PathStatus.Success then
    local waypoints = path:GetWaypoints()

    for i, waypoint in waypoints do
        local p = Instance.new("Part")
        p.Parent = workspace
        p.Size = Vector3.new(1,1,1)
        p.Position = waypoint.Position
        p.Anchored = true
        p.CanCollide = false
        p.Color = Color3.new(1,0,0)
        hum:MoveTo(waypoint.Position)
        hum.MoveToFinished:Wait()
    end
else
    warn("path unsuccessful")    
end

end)

foggy iris
plush void
#

oh ok

#

how do i do that then?

foggy iris
#

You can fix that by adding AgentHeight and AgentMaxSlope into the parameters, and also making sure you only set AgentCanClimb

#

atleast what i think im not 100% sure

plush void
#

k

#

what exactly does agent height do btw?

#

cuz ive messed around with it for a bit with no results

foggy iris
plush void
#

ah k

worthy yachtBOT
#

studio** You are now Level 1! **studio

foggy iris
#

Say your NPC’s actual model is 5 studs tall:

local path = PS:CreatePath({ AgentHeight = 5 })

It will go through a tunnel that’s 6 studs high.

It won’t go through a doorway that’s only 4 studs high pathfinding will avoid it entirely.

plush void
#

how do i send image cuz i think i found something that may b related

foggy iris
#

dms?

plush void
#

ig

#

so i sent the images

#

i cant rlly use costs cuz im my game everything is mostly just plastic