Weird Pathfinding Behavior

Not sure if this is intended or not but I see no reason why this rig shouldn’t be able to
move to my location when I get too close to the part. For the record this is just an example - I will not be actually calling :ComputeAsync() in a loop like this

Anything I can mess with in :CreatePath() parameters or other areas to potentially change this behavior?

2 Likes

Could you show your code?

(ignore)

local temporaryWaypoints = {}
local function pathfindTo(position)
	local path = game:GetService("PathfindingService"):CreatePath({
		AgentCanJump = false,
	})

	path:ComputeAsync(rig.PrimaryPart.Position, position)
	
	for _,v in pairs(temporaryWaypoints) do
		v:Destroy()
	end
	
	local waypoints = path:GetWaypoints()	
	for _,v in pairs(waypoints) do
		local waypoint = createWaypoint(v.Position, Color3.fromRGB(255, 0, 0))
		table.insert(temporaryWaypoints, waypoint)
	end	
end

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		while task.wait() do
			pathfindTo(character.PrimaryPart.Position)			
		end
	end)
end)
1 Like

seems like an issue with “AgentCanJump” being set to false – for whatever reason when I set it to true it arbitrarily decides to have the dummy go over the block

1 Like

That is pretty much normal behavior. I’m guessing that whenever you are very near the part, PathfindingService can only find a path that revolves jumping on top of the part.

The pathfinding service is officially used to find the shortest (and least cost) path from point A to point B for an NPC. If the hight of the block is less than about 7.5 studs, and the AgentCanJump flag is true, then the pathfinding service will issue a jump at the appropriate location. The rig will get to you when you get close to the part even though it’s not showing on your screen.

In Studio, go to File > Studio Settings > Studio. At the bottom of the list there is a group called visualization. The first item under that is Show Navigational Mesh. Check that so you can see what Roblox thinks the navigational map is. Everywhere that’s colored is where an agent can reach. Elevated places that can be reached will have arrows.

1 Like

Interesting – I was under the impression that if “AgentCanJump” was false and the rig had the ability to jump that it would just go around rather than treating it as not traversable. Thank you very much.

Unless AgentCanJump is true, the agent and the target are both on the same plane, so the pathfinding service will just walk the agent around the part even though it’s not visualized properly on the OP’s screen.

Are you sure it just isn’t visualized properly? Printing path.Status outputs “Enum.PathStatus.NoPath” when I am close to the block, hence the lack of visualization in the video I sent.

That’s the thing. If that setting is false, it will go around. This is standard behavior. The pathfinding service uses Dijkstra’s algorithm to resolve the path. When the jump setting is false, those nodes are excluded from the navigational graph, so it just finds a way around it.

If it does say NoPath, then that is strange. Can you post a screenshot with the navigational mesh turned on?

I don’t see any dead spots in the mesh. See those lines going up the side of the block? See how they have arrows on them? That means that the agent can jump to get up there. I’m looking at your code and I noticed that you are using the PrimaryPart for the position? What is the primary part? I do know that if the destination coordinates are inside a block, the result will be NoPath. So if part of your avatar is inside the block, it won’t path to it.

The PrimaryPart is the HumanoidRootPart on both the dummy and me, so torso area. Would changing the pathfinding destination to a point directly between my character’s feet solve the issue potentially?

I just actually tested this and it worked. For whatever reason when it was trying to pathfind directly to my torso’s position it failed to compute the path, but when I moved the destination point to the one I mentioned above there were no issues when I got close to the barrier. Very strange.

2 Likes

Possibly. But for my NPCs, I’m targeting them with the players HumanoidRootPart for R15 or Torso for R6 and I have noticed some glitching every now and then. You issue seems to be quite consistent. In the video, I noticed that your right arm is inside the block when the problem occurs. That, or you are right on the edge of the map when it transitions to a jump and it thinks you are too close to that dead zone around the part. Part of the agent options when you create the path object is the size of the agent. Or I should say the size of the required opening for the agent to pass through.

1 Like

Same behavior for me aswell. The AI fails to pathfind whenever I track the HumanoidRootPart, but succeeds whenever I track the leg.

I guess I’ll take this to note then.

Hmm… I wonder if the head would be a viable tracking target then.

Using the head as the tracking target results in the same questionable behavior as above with AgentCanJump set to false. Slightly worse actually.

1 Like

This may be an engine bug. The HumanoidRootPart is supposed to be the primary part of the R15 character model and therefore should be used for tracking. Beyond that, I have no other explanation.