AI - Move directly toward player when nothing blocking

I would like the AI to head straight for the player if no blocking objects in the nav mesh. I have got line casting working but am having problems setting the path. I tried the following from previous comments on another thread. SeachPath() in AIBase has been modified like so:

RecastGraph navmesh = (RecastGraph)AstarPath.active.data.FindGraphOfType(typeof(RecastGraph));
if (navmesh.Linecast(start, end))
{
seeker.StartPath(start, end);
}
else
{
//Fake a straight path to the target
straightLinePath = ABPath.Construct(start, end, null);
straightLinePath.vectorPath.Add(start);
straightLinePath.vectorPath.Add(end);
straightLinePath.CompleteState = PathCompleteState.Complete;
OnPathComplete(straightLinePath);
}

The AI simply stops when the path is not blocked. I have also tried adding the line: seeker.StartPath(straighLinePath) at the end. I then get errors about “path already processed” or “parameter index out of range”.

Hi

Which movement script are you using? AIPath or RichAI?
Could you show me the whole modified method?

I am using RichAI. I have tested the linecast functionality and that works fine. Just a few lines added to your method in AIBase:

public virtual void SearchPath()
{
if (float.IsPositiveInfinity(destination.x)) return;
if (onSearchPath != null) onSearchPath();

        lastRepath = Time.time;
        waitingForPathCalculation = true;

        seeker.CancelCurrentPathRequest();

        Vector3 start, end;
        CalculatePathRequestEndpoints(out start, out end);

        // Alternative way of requesting the path
        //ABPath p = ABPath.Construct(start, end, null);
        //seeker.StartPath(p);

        // This is where we should search to
        // Request a path to be calculated from our current position to the destination

        RecastGraph navmesh = (RecastGraph)AstarPath.active.data.FindGraphOfType(typeof(RecastGraph));
        if (navmesh != null)
        {
            if (navmesh.Linecast(start, end))
            {
                seeker.StartPath(start, end);
            }
            else
            {
                ////Fake a straight path to the target
                straightLinePath = ABPath.Construct(start, end, null);
                straightLinePath.vectorPath.Add(start);
                straightLinePath.vectorPath.Add(end);
                straightLinePath.CompleteState = PathCompleteState.Complete;
                OnPathComplete(straightLinePath);
                seeker.StartPath(straightLinePath);
            }
        }
        else
        {
            seeker.StartPath(start, end);
        }
    }