ReachedDestination returning false maybe wrong

The method RichAI.reachedDestination is returning false because of this logic: distanceToSteeringTarget + movementPlane.ToPlane(destination - richPath.Endpoint).magnitude > endReachedDistance

The destination is further than endReachedDistance away from richPath.Endpoint. I don’t understand the logic of comparing these two values? It results in the agent getting stuck because it can never reach the destination.

Note: approachingPartEndpoint and richPath.IsLastPart are both true.

The agent will move to richPath.Endpoint and as this is the last part of the path, richPath.Endpoint will never get closer to destination and so reachedDestination will never return true.

Could you please explain why richpath.Endpoint and destination are compared in this method? I am trying to work out why the agent is getting stuck in this situation and I am not following this logic.

I am on V4.2.18 using a recast graph.

        public bool reachedDestination
        {
            get
            {
                if (!reachedEndOfPath) return false;
                // Note: distanceToSteeringTarget is the distance to the end of the path when approachingPathEndpoint is true
                if (approachingPathEndpoint && distanceToSteeringTarget + movementPlane.ToPlane(destination - richPath.Endpoint).magnitude > endReachedDistance) return false;

                // Don't do height checks in 2D mode
                if (orientation != OrientationMode.YAxisForward)
                {
                    // Check if the destination is above the head of the character or far below the feet of it
                    float yDifference;
                    movementPlane.ToPlane(destination - position, out yDifference);
                    var h = tr.localScale.y * height;
                    if (yDifference > h || yDifference < -h * 0.5) return false;
                }

                return true;
            }
        }

Hi

It sounds like you might want to use ai.reachedEndOfPath instead.

1 Like