/// <summary> /// This method calls the currentNode's Constrain() method, and then uses the returned position /// and rotation data to modify this object's position and rotation. If Constrain() returns /// a new PathNode, the new node is stored as currentNode and then the method calls itself /// to re-attmempt projection. /// </summary> /// <param name="recursions">This keeps track of how many times the method has recursed. Recursion should only happen once, but if it happens 3 or more times an Exception is thrown.</param> void ProjectionOntoPath(int recursions = 0) { if (!currentNode) { return; } if (recursions > 2) { throw new System.Exception("Recursive path switching in AlignWithPath. This shouldn't happen. Submit a bug to the issue tracker."); } PathNode.ProjectionResults results = currentNode.Constrain(transform); if (results.newNode != null) { currentNode = results.newNode; ProjectionOntoPath(recursions + 1); } else { if (!float.IsNaN(results.percent)) { percentValueOnPath = results.percent; } results.position.y = transform.position.y; transform.rotation = results.rotation; transform.position = results.position; } }