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?
EDIT:
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.