public IEnumerator TurnToFace(Vector3Int target) { if (!AEUtilities.CheckGridLinear(AEUtilities.PosToInt(transform.position), target)) { yield break; } Vector3Int trueTarget = AEUtilities.GetAdjacentInt(AEUtilities.PosToInt(transform.position), target); int numRightTurns = 0; if (AEUtilities.PosToInt(transform.right * -1) == trueTarget) { adjusting = true; animator.SetTrigger("turn_left"); yield return(null); while (!animator.GetCurrentAnimatorStateInfo(0).IsName("idle")) { yield return(null); } adjusting = false; } else if (AEUtilities.PosToInt(transform.right) == trueTarget) { numRightTurns = 1; } else if (AEUtilities.PosToInt(transform.forward * -1) == trueTarget) { numRightTurns = 2; } else { yield break; } adjusting = true; for (int i = 0; i < numRightTurns; i++) { animator.SetTrigger("turn_right"); yield return(null); while (!animator.GetCurrentAnimatorStateInfo(0).IsName("idle")) { yield return(null); } } adjusting = false; }
private static void TurnToFace(GameObject o, Vector3Int target) { if (AEUtilities.CheckGridLinear(AEUtilities.PosToInt(o.transform.position), target)) { Vector3Int adjTarget = AEUtilities.GetAdjacentInt(AEUtilities.PosToInt(o.transform.position), target); if (adjTarget == AEUtilities.PosToInt(o.transform.position + o.transform.right)) { o.GetComponent <Animator>().SetTrigger("turn_right"); } else if (adjTarget == AEUtilities.PosToInt(o.transform.position + o.transform.right * -1)) { o.GetComponent <Animator>().SetTrigger("turn_left"); } else if (adjTarget == AEUtilities.PosToInt(o.transform.position + o.transform.forward * -1)) { o.GetComponent <Animator>().SetTrigger("turn_180"); } } }