Hey,
I’m trying to make my characters find the path around their target(if they have one). So I created the class “MyEndingCondition” as in example:
public class MyEndingCondition : ABPathEndingCondition
{
// Maximum world distance to the target node before terminating the path
public float maxDistance = 10;
// Reuse the constructor in the superclass
public MyEndingCondition(ABPath p) : base (p) { }
public override bool TargetFound(PathNode node)
{
return ((Vector3)node.node.position - abPath.originalEndPoint).sqrMagnitude <= maxDistance * maxDistance;
}
}
And I’ve tried to use it in overrided SearchPath function:
public override void SearchPath()
{
if (float.IsPositiveInfinity(destination.x) || pObj.isDead()) return;
if (onSearchPath != null) onSearchPath();
lastRepath = Time.time;
waitingForPathCalculation = true;
seeker.CancelCurrentPathRequest();
shouldSearch = true;
if (pObj.target != null)
{
if ((transform.position - pObj.target.transform.position).magnitude < pObj.person.activeInteraction.activationDistance)
{
isStopped = true;
shouldSearch = false;
}
else
{
float maxDistance = pObj.person.activeInteraction.activationDistance * 0.7f;
seeker.startEndModifier.exactEndPoint = StartEndModifier.Exactness.Original;
customPath = ABPath.Construct(tr.position + tr.up * (rvo.center - rvo.height * 0.5f), destination);
MyEndingCondition end = new MyEndingCondition(customPath);
end.maxDistance = maxDistance;
}
}
else
{
seeker.startEndModifier.exactEndPoint = StartEndModifier.Exactness.Original;
customPath = ABPath.Construct(tr.position + tr.up * (rvo.center - rvo.height * 0.5f), destination);
if (destination == transform.position)
shouldSearch = false;
}
if (seeker is CultSeeker)
(seeker as CultSeeker).ThatWasAnOrder = order;
if (shouldSearch)
{
seeker.StartPath(customPath);
if (order)
{
AstarPath.BlockUntilCalculated(customPath);
if (clickParticle != null) Destroy(clickParticle);
if (customPath.vectorPath.Count > 0)
{
Vector3 InstantiationPosition = customPath.vectorPath[customPath.vectorPath.Count - 1];
if((InstantiationPosition - destination).magnitude< 0.1f)
Debug.LogError("ICG.Testing - Something's wrong");
clickParticle = Instantiate(CGC.i.PrefabsManager.Particles.ClickedOnMap, InstantiationPosition + Vector3.up * 0.5f, Quaternion.identity);
correctPath = customPath.vectorPath;
}
else
{
clickParticle = Instantiate(CGC.i.PrefabsManager.Particles.ClickedOnMap, destination + Vector3.up * 0.5f, Quaternion.identity);
}
movementPathController.DrawMovementPath (correctPath);
order = false;
}
}
}
GIF:
It works, but somehow it takes a lot of time to start moving when the agent has the target. Did anyone else had this issue?