void GetNewPath(PathNode pathNode) { //if we're trying to get a new path at a visited node that isn't the last one we visited, we're trying to crossover and should stop. if (pathNode.IsVisited() && travelPath.Count > 0 && travelPath.Peek() != pathNode) { Debug.Log("Flashing!"); puzzle.lineWarning.Flash(); return; } //pop the node we're at off the travel stack if it's on it (gets readded later so long as we're not doubling back) if (travelPath.Count > 0 && travelPath.Peek() == pathNode) { travelPath.Pop(); } //determine best neighbor to path to next based on mouse delta Vector3 mouseDelta = MouseScreenToWorldPoint() - mousePosLast; List <PathNode> neighbors = puzzle.GetNeighborsOf(pathNode); PathNode bestNeighbor = neighbors[0]; float mouseDeltaDotBest = -2f; foreach (PathNode neighbor in neighbors) { float curDotPath = Vector2.Dot(mouseDelta.normalized, (neighbor.transform.position - pathNode.transform.position).normalized); if (curDotPath > mouseDeltaDotBest) { bestNeighbor = neighbor; mouseDeltaDotBest = curDotPath; } } //set node's visited status //if best neighbor isn't part of travel path then add this node to travel path and set as traveled if (!(travelPath.Count > 0 && travelPath.Peek() == bestNeighbor)) { pathNode.SetVisted(true); if (travelPath.Count > 0) { Edge e = puzzle.GetEdge(pathNode, travelPath.Peek()); e.line.GetComponent <MeshRenderer>().material = puzzle.lineVisitedMat; } nearTrail.startAnchor = pathNode.gameObject; travelPath.Push(pathNode); } //if best neighbor is part of travel path then we're backtracking. else { pathNode.SetVisted(false); if (travelPath.Count > 0) { Edge e = puzzle.GetEdge(pathNode, travelPath.Peek()); e.line.GetComponent <MeshRenderer>().material = puzzle.lineUnvisitedMat; nearTrail.startAnchor = travelPath.Peek().gameObject; } else { nearTrail.startAnchor = gameObject; } } nearTrail.Refresh(); //set new path anchors anchorA = pathNode.gameObject.transform; anchorB = bestNeighbor.gameObject.transform; if (lerpDist > pathNode.snapRadius / Vector2.Distance(anchorA.position, anchorB.position)) { lerpDist = 0f; } }