#Pathfinding running into walls

9 messages · Page 1 of 1 (latest)

cinder nymph
#

Hello I have a pathfinding script that makes an npc walk around randomly and he walks to places but just doesnt consider walls and will just walk right into them.

#

the green spheres are waypoints that it generated btw

#

and as you could see in the image the are placed like the wall isnt there

lusty urchin
#

does the wall have a collisiongroup?

cinder nymph
#

no

cinder nymph
ruby galleon
#

local PFS = game:GetService("PathfindingService")

local MovementArea = workspace.house.MovementArea
local path = PFS:CreatePath({
AgentRadius = 6,
AgentHeight = 5, -- Ensure correct agent height
AgentCanJump = false,
AgentCanClimb = false
})

local humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
local humanoidRoot = script.Parent:FindFirstChild("HumanoidRootPart")

local function followPath(destination)
-- Compute the path
local success, errorMessage = pcall(function()
path:ComputeAsync(humanoidRoot.Position, destination)
end)

if success and path.Status == Enum.PathStatus.Success then
    local waypoints = path:GetWaypoints()
    local nextWaypointIndex = 2

    -- Move through waypoints
    for _, point in ipairs(waypoints) do
        if point.Action == Enum.PathWaypointAction.Jump then
            humanoid.Jump = true
        end
        humanoid:MoveTo(point.Position)
        humanoid.MoveToFinished:Wait()
    end
else
    warn("Path not computed!", errorMessage)
end

end

while true do
wait(math.random(5, 10))

-- Pick a random point inside MovementArea
local X = math.random(-MovementArea.Size.X/2, MovementArea.Size.X/2)
local Z = math.random(-MovementArea.Size.Z/2, MovementArea.Size.Z/2)
local destination = MovementArea.Position + Vector3.new(X, 0, Z)

-- Compute a test path to see if it's reachable
local testPath = PFS:CreatePath({ AgentRadius = 6, AgentCanJump = false })
testPath:ComputeAsync(humanoidRoot.Position, destination)

if testPath.Status == Enum.PathStatus.Success then
    followPath(destination)
else
    warn("Invalid path, choosing a new point.")
end

end
try this

cinder nymph
#

I actually figured out the issue, the wall in between was a union which I wouldnt believe would be an issue but it worked once I changed the wall for a normal part

acoustic igloo