public Vector3 GetFurthestAisleExit(Vector3 position) { //figure out which side of the aisle we are closest to Vector3 nearestLeft = GetNearestNode(position, AisleSide.Left); float leftDist = Vector3.Distance(position, nearestLeft); Vector3 nearestRight = GetNearestNode(position, AisleSide.Right); float rightDist = Vector3.Distance(position, nearestRight); AisleSide furthestSide = leftDist < rightDist ? AisleSide.Right : AisleSide.Left; //get closest exit node for the other side of the aisle# return(GetNearestNode(position, furthestSide)); }
public Vector3 GetNearestNode(Vector3 position, AisleSide sides) { List <Vector3> nodes = new List <Vector3>(); if (sides.HasFlag(AisleSide.Left)) { nodes.AddRange(leftNodes); } if (sides.HasFlag(AisleSide.Right)) { nodes.AddRange(rightNodes); } if ((int)sides == 0) { Debug.LogError("No nodes to search for when locating nearest node."); } Vector3 chosenNode = position; float minDistance = Mathf.Infinity; foreach (Vector3 n in nodes) { float distance = Vector3.Distance(n, position); if (distance < minDistance) { chosenNode = n; minDistance = distance; } } return(chosenNode); }