Basically as the title says, I want the seeker to ignore paths that aren’t possible and ONLY choose one that it’s able to reach. Here’s my failed attempt:
using UnityEngine;
using System.Collections;
using Pathfinding;
public class WanderRandom : MonoBehaviour
{
public float radius = 20;
IAstarAI ai;
void Start()
{
ai = GetComponent<IAstarAI>();
}
void PickRandomPoint(out Vector3 closestPointOnGraph, out bool possible, out Pathfinding.ABPath path)
{
var point = Random.insideUnitSphere * radius;
var pointOnGraph = AstarPath.active.GetNearest(point, NNConstraint.Default);
var node1 = AstarPath.active.GetNearest(transform.position).node;
var node2 = AstarPath.active.GetNearest(point).node;
possible = PathUtilities.IsPathPossible(node1, node2);
var closestPoint = pointOnGraph.position;
closestPoint.y = 0;
closestPoint += ai.position;
closestPointOnGraph = closestPoint;
path = ABPath.Construct(transform.position, point);
}
void Update()
{
Vector3 i;
bool a;
Pathfinding.ABPath path;
PickRandomPoint(out i, out a, out path);
print(a);
// 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.reachedEndOfPath || !ai.hasPath))
{
AstarPath.StartPath(path);
path.BlockUntilCalculated();
if(a){
ai.destination = i;
ai.SearchPath();
}
}
// var closestPointOnGraph = PickRandomPoint();
// var path = ABPath.Construct(transform.position,closestPointOnGraph);
// var pathLength = path.GetTotalLength();
// Debug.Log(pathLength);
Debug.DrawLine(transform.position, ai.destination, Color.magenta);
}
}
As it is, I’m able to see in the console that the seeker is pursuing paths that are impossible, and so he gets stuck while trying to pass through a wall. I should mention that this script draws from the WanderingAI tutorial and I’m using a grid graph.
I’m new to all of this so any help with this issue/guidance on improving my script would be incredible, thanks!