Flanking with PathfindingService

I’ve been trying to make an agent take flanking routes to its destination. I know when the agent has to take a flanking route (just raycast to see if a waypoint is in the line of sight), but I don’t know how to get that path using PathfindingService.

Suppose the following scenario: there is an agent and its target separated by a wall. The agent wants to get to its target without being seen. The shortest path is to walk in front of the target’s line of sight - but that means the agent would be seen. The flanking path is to go around the other way, like shown here:

The green lines indicate where the target can see, the red line indicates the shortest path and the blue line indicates the flanking path (the path that I want to get).

Is there any way to do this with PathfindingService, or will I have to use an alternative pathfinding algorithm?

1 Like

You could create a hitbox for where you dont want the npc to go, and set the cost of that hitbox in the parameters to a higher number so the npc will try to avoid it.

I’ve considered this but it might be hacky and expensive (and probably inaccurate) to create that hitbox dynamically. If there’s no other solution, I’ll probably just have to make do with that.