public Vector3 AimAwayFromNeighbourhood(Vector3 randPt) { Vector3 newAngle = randPt; float largestDistFromTree = 0; PathNode freshestNode = root; Vector3 freshestAngle = randPt; // Check 18 different angles around the clock for boundaries/free space for (int i = 0; i < 18; i++) { // Find closest node in tree to the random pt we have chosen PathNode closestNode = root.ClosestNode(newAngle); // Agent is closer to unexplored space than the tree is float distFromTree = Vector3.Distance(closestNode.position, newAngle); if (Vector3.Distance(this.agentLoc.position, newAngle) < distFromTree) { return(newAngle); } if (largestDistFromTree < distFromTree) { // if(freshestNode.Depth() > closestNode.Depth()) { freshestAngle = newAngle; freshestNode = closestNode; } // rotate clockwise by 40degrees newAngle = Quaternion.Euler(20, 0, 0) * (newAngle - this.agentLoc.position) + this.agentLoc.position; } return(freshestAngle); }