Help needed with wandering AI

Hello everybody, I’m very new to this so maybe somebody here can help me with this question.

I was following the Wandering AI tutorial on this website, and I get the error

“Error CS1061 ‘IAstarAI’ does not contain a definition for ‘targetReached’ and no accessible extension method ‘targetReached’ accepting a first argument of type ‘IAstarAI’ could be found (are you missing a using directive or an assembly reference?)”

But in the documentation on this topic, it clearly states that there is a targetReached that I should be able to reference.

What I’m I doing wrong?

Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;

public class Roaming2DAstar : MonoBehaviour
{
public float radius = 20;
IAstarAI ai;

void Start()
{
    ai = GetComponent<IAstarAI>();
}
Vector3 PickRandomPoint()
{
    var point = Random.insideUnitSphere * radius;
    point.y = 0;
    point += ai.position;
    return point;
}
void Update()
{
    // Update the destination of the AI if
    // the AI is not already calculating a path and
    // the ai has reached the end of the path or it has no path at all
    if (!ai.pathPending && (ai.targetReached || !ai.hasPath))
    {
        ai.destination = PickRandomPoint();
        ai.SearchPath();
    }
}

}

Hi

You are looking at old documentation. Take a look at the more up-to-date documentation at Wandering AI Tutorial - A* Pathfinding Project

1 Like