public Pair <Double, Vector3> SearchGrid(WorldAgent newAgent, int newX, int newY, double currClosestDistance, Vector3 targetDirection) { foreach (WorldAgent nearestNeighbor in _agentGrid[newX, newY]) { double newDistance = newAgent.FindDistance(nearestNeighbor); if (newDistance < currClosestDistance) { currClosestDistance = newDistance; targetDirection = nearestNeighbor.transform.position; } } return(new Pair <Double, Vector3>(currClosestDistance, targetDirection)); }
public Pair <Double, Vector3> SearchGrid(WorldAgent newAgent, int newX, int newY, double currClosestDistance, Vector3 targetDirection, Vector3 simForward) { foreach (WorldAgent nearestNeighbor in _agentGrid[newX, newY]) { double newDistance = newAgent.FindDistance(nearestNeighbor); if (newDistance < currClosestDistance && newDistance < GetSettingFloat("ViewRange")) { Vector3 targDirection = nearestNeighbor.transform.position - newAgent.transform.position; float angleToNearestNeighbor = Vector3.Angle(simForward, targDirection); if (angleToNearestNeighbor < GetSettingFloat("ViewAngle") / 2) { currClosestDistance = newDistance; targetDirection = nearestNeighbor.transform.position; } } } return(new Pair <Double, Vector3>(currClosestDistance, targetDirection)); }