Hi, I have been faced with a challenge for a few days and I’m looking for outside input.
I have AI that make use of the PathfindingService to plot courses above ground when wandering.
They don’t behave so well underground
See, the way they choose a new destination is by generating a Ray above themselves that points directly downwards, using :FindPartOnRay() for its part and position arguments, then they :FindPathAsync() and follow the points leading to the destination.
The Ray that determines the new destination is ± 50 studs either direction on the X and Z axis and 100 studs higher than the creature. This means that my system does not work in caves where the ceiling is low. Simply reducing the height of the ray is not enough for a couple reasons, chief among which that it would fail if the creature was against the wall of a tunnel where the ceiling tapers close to the head.
My initial thought is that I could manually map the cave systems with nodes at every junction, and they just pick a random node to path to. I’d really rather not do that, chiefly because of scalability, but I will if no better solutions are presented.
My second idea is to send a ray between themselves and the roof of the cave, and use the midpoint of that ray to then project another ray laterally until it exceeds a distance of at least 5 studs without hitting anything, and then a third ray downward from that point to determine the final destination. This runs into problems if parts of the cave roof are twice as tall as the rest and narrower than 5 studs. It would get infinitely stuck. It also means a lot of recursion. It also means they can’t navigate corners easily, and they will have a slight tendency to go downwards instead of upwards on narrow slopes.
Dynamically moving these AI each frame using raycast sensory mechanisms is not feasible for the scope of my project. All AI will use simple A to B course determination. This will allow me to manage hundreds if not thousands simultaneously.
What would you do?