Can't seem to get AI to move along vertical paths


I am having some issue getting my AI character to move along vertical paths.

I am using a LocalSpaceRichAI script, a Seeker script, and a very simple custom movement script that I wrote that basically just sets the AI destination:

if (ai != null) ai.destination = AIdestpos.transform.position;

This works fine for flat meshes, but I have recently added a stairs. The actual collision box of the stairs is a simple ramp, with no steps, etc, and the navmesh is generated perfectly. In addition, the AI’s path also navigates around the stairs perfectly, as can be seen here:

if (ai != null) ai.destination = AIdestpos.transform.position;

The green line is the path that the nav system has generated for the ai, and it clearly follows the staircase (the actual ramp collision mesh is invisible, the steps themselves have no collision).

The AI (the sphere) is supposed to be following the path vertically (as can be seen by the blue line) but it never changes its height, it just moves around and around in circles, continuously regenerating its path, but never getting higher.

I am guess I need to use a different character controller for this?

What would be the easiest way to add height support to my current ai controller?


It sounds like the RichAI’s ground physics raycast is not hitting the stair collider. Can you double check the layers set on the RichAI component?

Hi, thanks for your reply.

You were right about the raycasting. It had something to do with gravity in my case, with no gravity, the raycast wasn’t firing?

I think I have fixed this with a fairly crude hack, I am just manually raycasting and setting the ai’s position based on that. There is probably a better way though.

In localspacerichai, I am just doing this:

if (Physics.Raycast(aipos, aivec, out hit, 4)) //distance of 10
Vector3 uvec = transform.up * 0.2f;
transform.position = hit.point + uvec;

It seems to work ok, but obviously needs some optimisation.

Another issue that I have just run into is when I am moving an AI onto a graph.

For my project, I want to be able to generate graphs in real time for buildings, structures, etc, and then move Ai characters onto those graphs.

Everything seems mostly fine, I can generate the graphs (or load them from a file) and the graphs look good and function (except for the issues going up stairs).

The only issue is with adding the Ai to the graphs when the building has moved. I have implemented the “moving” example scripts, and this works when the graphs are created at level load time, but I am now noticing some issues when creating the graphs during runtime.

Is there some particular way to move the AI to the graph at run time?


This is the main error that I am getting:

IndexOutOfRangeException: Index was outside the bounds of the array.
Pathfinding.NavmeshTile.GetVertexInGraphSpace (System.Int32 index) (at Assets/AstarPathfindingProject/Generators/Utilities/NavmeshTile.cs:63)
Pathfinding.NavmeshBase.GetVertexInGraphSpace (System.Int32 index) (at Assets/AstarPathfindingProject/Generators/NavmeshBase.cs:176)
Pathfinding.TriangleMeshNode.GetVerticesInGraphSpace (Pathfinding.Int3& v0, Pathfinding.Int3& v1, Pathfinding.Int3& v2) (at Assets/AstarPathfindingProject/Generators/NodeClasses/TriangleMeshNode.cs:105)
Pathfinding.TriangleMeshNode.ContainsPointInGraphSpace (Pathfinding.Int3 p) (at Assets/AstarPathfindingProject/Generators/NodeClasses/TriangleMeshNode.cs:203)
Pathfinding.TriangleMeshNode.ContainsPoint (UnityEngine.Vector3 p) (at Assets/AstarPathfindingProject/Generators/NodeClasses/TriangleMeshNode.cs:196)
Pathfinding.RichFunnel.ClampToNavmeshInternal (UnityEngine.Vector3& position) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:483)
Pathfinding.RichFunnel.Update (UnityEngine.Vector3 position, System.Collections.Generic.List`1[T] buffer, System.Int32 numCorners, System.Boolean& lastCorner, System.Boolean& requiresRepath) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:435)
Pathfinding.RichAI.UpdateTarget (Pathfinding.RichFunnel fn) (at Assets/AstarPathfindingProject/Core/AI/RichAI.cs:323)
Pathfinding.RichAI.TraverseFunnel (Pathfinding.RichFunnel fn, System.Single deltaTime, UnityEngine.Vector3& nextPosition, UnityEngine.Quaternion& nextRotation) (at Assets/AstarPathfindingProject/Core/AI/RichAI.cs:365)
Pathfinding.RichAI.MovementUpdateInternal (System.Single deltaTime, UnityEngine.Vector3& nextPosition, UnityEngine.Quaternion& nextRotation) (at Assets/AstarPathfindingProject/Core/AI/RichAI.cs:350)
Pathfinding.AIBase.MovementUpdate (System.Single deltaTime, UnityEngine.Vector3& nextPosition, UnityEngine.Quaternion& nextRotation) (at Assets/AstarPathfindingProject/Core/AI/AIBase.cs:403)
Pathfinding.AIBase.FixedUpdate () (at Assets/AstarPathfindingProject/Core/AI/AIBase.cs:395)

I’m not sure what is causing this. This doesn’t happen when I generate the graphs at the beginning of the game (before the objects have moved), but if I dynamically place an object at an arbitrary location, and then generate (or load a graph from a file) I get the above error repeated in the console.