AILerp reached a target

Hi.
To move AI I use the AILerp.
Could you please tell me, how to check that my AI reached a target on a map(passed all distance)?

I’ve found OnTargetReached, but it’s called every time, when it reach a closest point.

Hi

The AILerp script only specifies when it has reached the end of the path (using e.g OnTargetReached or in the beta using the reachedDestination property). If it has reached the target is very game specific as there are varying thresholds for what games will allow. I suggest simply checking the distance to the destination and checking if that is lower than some threshold.

Maybe it is better to use AIPath for it?

Hi

The AIPath script does the same thing. It is very hard for my package to know what your game will consider “reached”.

I understand. I have a game board with balls, small ghost(AI) and a big ghost(target). So, a player need to destroy a balls, and let the small ghost(AI) to rich the target - the big ghost(in the end of path the small ghost should be near the big host).

I’ve created a small test project. Added AIPath to my AI but it’s doesn’t move

Hi

In the current version unfortunately the AIPath script only works in 2D for grid, navmesh and recast graphs. Not for point graphs. The reason is that point graphs have no well defined up direction, so the AIPath script assumes it is a normal 3D game. I suppose it should fall back to a 2D assumption if the ‘rotate in 2D’ option is true though… I should fix that.

If you open the AIPath.cs script you can replace this line

``````movementPlane = graph != null ? graph.transform : GraphTransform.identityTransform;
``````

with this

``````movementPlane = graph != null ? graph.transform : (rotationIn2D ? new GraphTransform(Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90, 270, 90), Vector3.one)) : GraphTransform.identityTransform);
``````

and then everything works assuming you also set the ‘rotationIn2D’ field to true. You will have to rotate back your sprite to a (0,0,0) rotation instead of the current one of (0,90,0) that you are using.