Pathfinding is creating a path with a bunch of waypoints close to each other in a line

Hi!

I’ve been developing an AI but ran into a little issue with pathfinding waypoints.

It looks like PathfindingService is generating a path with a bunch of tightly packed waypoints in a line (hold note lookin’)
image

I’ve tried looking for other posts like this but couldn’t find anyone with this issue.
My code has also set WaypointSpacing to 8, which does work, but still these “hold note” paths are made

Does anyone know what could cause this?

(Here’s the path that it uses for context)

local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath({
	AgentRadius = 5,
	AgentHeight = 5,
	AgentCanJump = false,
	WaypointSpacing = 8,
	Costs = {
		Water = 20,
		Mud = 2,
		Grass = 2,
		ForestGrass = 2,
		Ground = 2,
		LeafyGrass2= 2,
		Snow = 2,
		Sand = 2,
	}
})

The AI individually walks to each one and stutters over it so I’d like those to not happen!

2 Likes

Hello, how can I help you today?

2 Likes

path:ComputeAsync(start, end)

local points = path:GetWaypoints()

for i = 1, #points do
local point = points[i]
print(point.Position)
end

Output:

Vector3(1,0,1)
Vector3(1,0,2)
Vector3(1,0,3)
Vector3(1,0,4)
Vector3(1,0,5)
Vector3(1,0,6)
Vector3(1,0,7)
Vector3(1,0,8)
Vector3(2,0,8)
Vector3(3,0,8)
Vector3(4,0,8)
Vector3(5,0,8)
Vector3(6,0,8)
Vector3(7,0,8)
Vector3(8,0,8)
Vector3(8,0,7)
Vector3(8,0,6)
Vector3(8,0,5)
Vector3(8,0,4)
Vector3(8,0,3)
Vector3(8,0,2)
Vector3(8,0,1)
Vector3(7,0,1)
Vector3(6,0,1)
Vector3(5,0,1)
Vector3(4,0,1)
Vector3(3,0,1)
Vector3(2,0,1)

2 Likes

local success, pos = path:ComputeAsync(startPoint, endPoint)

2 Likes

Hi! Thanks for the reply, but how does this apply to my question?

I’m not sure how this is helpful to my situtation.

I understand how to create a path, interate over the waypoints, etc.

2 Likes

I’m having the same issue. Did you find any solution to it?

1 Like

:person_facepalming:

bro…

just loop through the waypoints table and verify that each waypoint is waypointSpacing distance away from each other - if its not, remove it

1 Like