public void MoveTo(Vector3 whereToStand, Vector3 lookAt, IMinigame mg) { mg.InAction(); scriptInvolvedInMoving = mg; stageMovement = false; moveToOtherPoint = true; lookAtPoint = lookAt; StartCoroutine(Rotate(whereToStand, true, true)); }
IEnumerator Rotate(Vector3 point, bool firstRotation, bool stop) { /*GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Sphere); * temp.transform.position = point; * temp.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);*/ if (!rotating) { rotating = true; point.y = bard.transform.position.y; Vector3 targetDir = point - bard.transform.position; Quaternion rotationQuat = Quaternion.Euler(0, 90, 0); Vector3 lineOfSight = rotationQuat * bard.transform.forward; // Choose the rotation-direction String direction; if (Vector3.Angle(targetDir, lineOfSight) > Vector3.Angle(targetDir, Quaternion.Euler(0, 1, 0) * lineOfSight)) { direction = "right"; } else { direction = "left"; } // Rotate bard towards point while (Vector3.Angle(targetDir, lineOfSight) > rotation) { control.RotateBard(direction); lineOfSight = rotationQuat * bard.transform.forward; yield return(new WaitForSeconds(0.01f)); } // Last rotation for angle = 0 control.RotateBard(direction, Vector3.Angle(targetDir, lineOfSight)); lineOfSight = rotationQuat * bard.transform.forward; if (!stop) { StartCoroutine(MoveOnStage(point, firstRotation)); } else if (stageMovement) { climbing = false; control.ModeChange(); board.ShowGuitar(bard.transform.position); start.Play(); } else if (moveToOtherPoint) { StartCoroutine(MoveToCR(point, lookAtPoint)); moveToOtherPoint = false; } else { if (scriptInvolvedInMoving != null) { scriptInvolvedInMoving.InAction(); scriptInvolvedInMoving = null; } stageMovement = true; } rotating = false; } }