Can NNConstraint check visibility?

I’m trying to build an automated system to spawn NPCs ahead of the player, have them pathfind past the player until they’re out of sight, then de-spawn and repeat. I know I can get a reference to a node a specific distance away from the player with Node node = AstarPath.active.GetNearest (transform.positon, NNConstraint.Default);, but looking at NNConstraint’s documentation I don’t see any way to check for line of sight. Is this functionality supported, or would I have to just continuously run GetNearest at the same distance until it returns a node that passes a subsequent LOS check?

Hi

No, that is not supported out of the box.
Good news is that you can extend it

public class MyNNConstraint : NNConstraint { public Vector3 target; override bool Suitable ( GraphNode node ) { return base.Suitable (node) && <line of sight check here>; } }

Perfect, thank you!!

This is much more esoteric and I didn’t find references to any related functionality in the docs, but is there a way to specify directionality when I’m searching for a node or assembling a path? Right now I’m abstracting “in front of”/“behind” the PC by grabbing a chunk of nodes and checking them against the player object’s facing, but I would feel silly if directionality was supported out of the box.

Hi

Not really, sorry.
It only uses the closest node by euclidean distance.

If you really want it I guess you could hack it by modifying the GetNearest method in the AstarPath.cs script.

Hmm okay, excellent- thank you again :slight_smile: