Hey
I’ve overrided the AIPath so my agents find paths depending on that if they have a target(which they interact with - like attack etc). Here’s the code of SearchPath():
public override void SearchPath()
{
if (float.IsPositiveInfinity(destination.x) || pObj.isDead()) return;
if (onSearchPath != null) onSearchPath();
lastRepath = Time.time;
if(true) //Nie wypierdalać
{
waitingForPathCalculation = true;
////if (!order)
seeker.CancelCurrentPathRequest();
}
canMove = true;
shouldSearch = true;
if (pObj.target != null)
{
if ((transform.position - destination).magnitude < pObj.person.activeInteraction.activationDistance)
{
canMove = false;
shouldSearch = false;
}
else
{
float maxDistance = pObj.person.activeInteraction.activationDistance * 0.7f;
seeker.startEndModifier.exactEndPoint = StartEndModifier.Exactness.Original;
customPath = XPath.Construct(tr.position + tr.up * (rvo.center - rvo.height * 0.5f), destination);
customPath.endingCondition = new EndingConditionProximity(customPath, maxDistance);
}
}
else
{
seeker.startEndModifier.exactEndPoint = StartEndModifier.Exactness.Original;
customPath = XPath.Construct(tr.position + tr.up * (rvo.center - rvo.height * 0.5f), destination);
if (destination == transform.position)
shouldSearch = false;
}
if (shouldSearch)
{
seeker.StartPath(customPath);
if (order)
{
AstarPath.BlockUntilCalculated(customPath);
if (clickParticle != null) Destroy(clickParticle);
if (customPath.vectorPath.Count > 0)
{
Debug.LogError("ICG.Testing - Path was found");
Vector3 InstantiationPosition = customPath.vectorPath[customPath.vectorPath.Count - 1];
clickParticle = Instantiate(CGC.i.PrefabsManager.Particles.ClickedOnMap, InstantiationPosition + Vector3.up * 0.5f, Quaternion.identity);
correctPath = customPath.vectorPath;
}
else
{
Debug.LogError("ICG.Testing - Path wasnt found");
clickParticle = Instantiate(CGC.i.PrefabsManager.Particles.ClickedOnMap, destination + Vector3.up * 0.5f, Quaternion.identity);
}
movementPathController.DrawMovementPath (correctPath);
order = false;
}
}
}
The problem is that when the agent has pObj.target and he’s trying to find a path to place around the target, it often does not. I’m getting warning:
Path Failed : Computation Time 2.00 ms Searched Nodes 2003
Error: Searched whole area but could not find target
Path Number 3361 (unique id)
UnityEngine.Debug:LogWarning(Object)
AstarPath:LogPathResults(Path) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:745)
AstarPath:m__2(Path) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1147)
Pathfinding.PathProcessor:CalculatePathsThreaded(PathHandler) (at Assets/AstarPathfindingProject/Core/Misc/PathProcessor.cs:358)
Pathfinding.c__AnonStorey1:<>m__0() (at Assets/AstarPathfindingProject/Core/Misc/PathProcessor.cs:95)
I’m using recast graph if that’s important.
Does anyone know how to solve this?