Pathfinding Problem

Hi,
I encounter this problem where Pathfinding is acting strange and not working. I have the following code:

function mobPathFinding(mob)
	
	local pathFinding = game:GetService("PathfindingService") 

	local path = pathFinding:CreatePath()
	local target = game.Workspace:WaitForChild("target")
	
	local success, err = pcall(function()
		path:ComputeAsync(mob.PrimaryPart.Position, target.PrimaryPart.Position)
	end)

	if success and path.Status == Enum.PathStatus.Success then

		local waypoints = path:GetWaypoints()
		
		for _, w in pairs(waypoints) do
			
			mob:MoveTo(w.Position)
			wait(.1)
			
		end
	else
		warn(err)
	end
end

If I write like this path:ComputeAsync(mob.PrimaryPart.Position, target.PrimaryPart.Position + Vector3.New(1, 0, 0)) then is computing the path. I don’t understand why is going like that. Any suggestions?

A few suggestions …

This helps (snip)

local Agents={WaypointSpacing=(5),
	AgentRadius=(1),AgentHeight=(0),
	AgentCanJump=(false),AgentCanClimb=(false),
	Costs={LeafyGrass=math.huge,SmoothPlastic=math.huge}} --< avoid moving over
local pf=game:GetService("PathfindingService")

path=pf:CreatePath(Agents)
path:ComputeAsync(PrimaryPart.Position,target)

a snippet

for i,waypoint in ipairs(waypoints)do
  local distance=(waypoint.Position-PrimaryPart.Position).Magnitude
  local duration=(distance/(Humanoid.WalkSpeed*1.033)) --⏳-- ajust
  (then do the) mob:MoveTo(waypoint.Position) task.wait(duration)

no need for the pcall

1 Like