I’ve written an AI using pathfinding service which wanders around the map by picking a random position, generating a path and moving to that position, and then repeating. Quite often though it generates points that for whatever reason pathfindingservice can’t find a valid path, to handle this I simply generate a new point and try that one instead. This works fine, but I’ve counted the number of failed and succesful paths and the failed paths are roughly 50% of the total paths I generate, which is obviously very inefficient.
The AI always finds a valid path in the end, but it can take between 5-10 tries in some cases, not ideal.
So is there any way I can reduce the number of paths which fail? For reference this is how I select my points:
targetPos = char.PrimaryPart.Position + Vector3.new(rng:NextInteger(50, 100) * rng:NextInteger(-1, 1), 0, rng:NextInteger(50, 100) * rng:NextInteger(-1, 1))
So it chooses a random x and z value between from -50 → -100 or 50 → 100 away from the character, then generates a Vector3 from these two values (y value is the same as the character’s).