/** * Calculates the turn direction based on the user position, next corner, and nextNext corner * Returns "left", "right", or "straight" if the target is far away or the goal is the next corner */ private string GenerateTurnInstruction(Vector3[] path, Vector3 currentUserPos) { // if the next corner is too far away OR the goal is the last corner, the user needs to go straight if (distanceToNextCorner >= maxDistanceToNextCorner || path.Length <= 2) { return("straight"); } var upwardsVector = Vector3.up; Quaternion targetAngle = Quaternion.LookRotation(nextCorner - currentUserPos); var unitVectorForward = targetAngle * Vector3.forward; Quaternion targetAngle2 = Quaternion.LookRotation(nextNextCorner - nextCorner); var unitVectorForward2 = targetAngle2 * Vector3.forward; // -1 = left, 1 = right, 0 = backwards/forwards var directionResult = HelperFunctions.AngleDir(unitVectorForward, unitVectorForward2, upwardsVector); if (directionResult == -1) { return("left"); } else { return("right"); // This ignores the forward/backward result by intention } }