I’m experimenting with a scene whereby not only is the surface of the world mesh walkable but so are subterranean caves. There will always be at least one entrance to the cave system from the surface and I’d like my AI character to be able to traverse this opening and plot routes from within the cave to the surface world (and vice-versa).
Below is an image that looks like a 5 year old drew it but was actually drawn by yours truly, and below that are two screen grabs of the relevant scene areas in Unity. Hopefully these illustrate sufficiently what I’m trying to do.
I’m using the Layered Grid Graph due to the overlapping walkable surfaces. When I scan the mesh to generate the navmesh, I notice that while the surface face is nicely covered there’s a gap between the entrance to the cave and the tunnel leading to the cave itself, as indicated in the screenshot by the unwalkable nodes. It’s also notable from the same screenshot that the surface navmesh area appears to “reach inside” the entrance to the tunnel, covering the entrance itself. According to the default colour scheme that shaded area indicates the boundary of the navmesh, so could the whole issue be due to there being no connection between the surface navmesh and the tunnel navmesh? How would one go about ensuring the tunnel can connect to the surface with a single navmesh or some method of bridging the two?
When I set my AI character - which I’ve placed in the cave - to navigate to the target object on the surface of the mesh, it initially begins moving towards the entrance but then warps to the surface and continues to move towards the target (albeit at a jaunty angle).
Interestingly, when I allow the AI character to “wander” aimlessly within the cave room it will occasionally warp to the surface directly above the cave room - usually when the AI character is walking along the walls.
What could be causing the warp? I thought it may be due to the gap in the calculated nav area from the cave tunnel to the surface (note: the character appears to warp when it reaches the first unwalkable node, even if there is a navmesh extending beyond that point), but that wouldn’t explain why the warp also sometimes happens within the cave room.
[Edit]: further testing reveals there are exceptions being thrown at the point of warping, and then repeatedly afterwards:
First exception, which reoccurs hundreds of times as the AI character warps and continues to move to the target:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
Pathfinding.AIPathAlignedToSurface.InterpolateNormal (RaycastHit hit) (at Assets/AstarPathfindingProject/Behaviors/AIPathAlignedToSurface.cs:48)
Pathfinding.AIPathAlignedToSurface.UpdateMovementPlane () (at Assets/AstarPathfindingProject/Behaviors/AIPathAlignedToSurface.cs:64)
Pathfinding.AIPathAlignedToSurface.Update () (at Assets/AstarPathfindingProject/Behaviors/AIPathAlignedToSurface.cs:14)
additional exception that occurs a dozen times or so after the initial warp:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[System.Int32].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
Pathfinding.AIPathAlignedToSurface.InterpolateNormal (RaycastHit hit) (at Assets/AstarPathfindingProject/Behaviors/AIPathAlignedToSurface.cs:48)
Pathfinding.AIPathAlignedToSurface.UpdateMovementPlane () (at Assets/AstarPathfindingProject/Behaviors/AIPathAlignedToSurface.cs:64)
Pathfinding.AIPath.OnPathComplete (Pathfinding.Path newPath) (at Assets/AstarPathfindingProject/Core/AI/AIPath.cs:274)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path p, Boolean runModifiers, Boolean sendCallbacks) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:299)
Pathfinding.Seeker.OnPathComplete (Pathfinding.Path path) (at Assets/AstarPathfindingProject/Core/AI/Seeker.cs:267)
Pathfinding.Path.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:728)
Pathfinding.Path.Pathfinding.IPathInternals.ReturnPath () (at Assets/AstarPathfindingProject/Core/Path.cs:782)
Pathfinding.PathReturnQueue.ReturnPaths (Boolean timeSlice) (at Assets/AstarPathfindingProject/Core/Misc/PathReturnQueue.cs:55)
AstarPath.Update () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:799)
[Edit 2]
I tried adding an AnimationLink between the tunnel entrance and the surface, and I noticed that a full path to the surface appeared to be plotted. However, as mentioned above, the AI still warps to the surface long before reaching the entrance.
Eventually I’d like to have multiple cave rooms and tunnels connected to each other and the surface, with the AI character able to nav from cave room to cave room as well as to the surface, so I’d love to be able to get on the right tracks at this early stage and clearly I can’t have the AI character warping around the place!
Any advice you can offer will be greatly appreciated .
Cheers!