IEnumerator RotateRoom(Vector3 nRotEuler) { Quaternion targetRotation = Quaternion.Euler(nRotEuler); m_rotationRefresh.Start(m_rotationSpeed); float elapsedTime = 0; while (!m_rotationRefresh.isDone) { elapsedTime += Time.deltaTime; //add time passed float rotationPercentage = elapsedTime / m_rotationSpeed; transform.localRotation = Quaternion.Lerp(transform.localRotation, targetRotation, rotationPercentage); yield return(m_rotationTick); } transform.localRotation = targetRotation; // getting rid of .000xx errors in the rotation; m_rotationRefresh.Start(m_rotationDowntime); m_rotating = false; yield break; }
public bool SetState(RoomRotatorState state, FaceDirection direction = FaceDirection.None) { if ((State & RoomRotatorState.ExecuteCombinedRotation) != 0) { return(false); } if ((state & RoomRotatorState.Idle) != 0) { State = state; return(true); } State |= state; if ((State & RoomRotatorState.ExecuteCombinedRotation) != 0 && m_CombinedRotationTimer.isDone) { m_CurrentFaceDirection = direction; //Pre rotate the dummy target transform to next Y 90 degree multiple then apply desired rotation //float currentYRot = m_DummyTransform.rotation.eulerAngles.y; //bool isNeg = currentYRot < 0; //currentYRot = kCombinedRotationAngle * (((isNeg ? Mathf.Abs(currentYRot) : currentYRot) - 1) / kCombinedRotationAngle + 1); //m_DummyTransform.Rotate(0, (isNeg ? -1 * currentYRot : currentYRot) - m_DummyTransform.rotation.eulerAngles.y, 0, Space.World); switch (m_CurrentFaceDirection) { case FaceDirection.Forward: m_DummyTransform.Rotate(kCombinedRotationAngle, 0, 0, Space.World); break; case FaceDirection.Backward: m_DummyTransform.Rotate(-kCombinedRotationAngle, 0, 0, Space.World); break; case FaceDirection.Left: m_DummyTransform.Rotate(0, 0, kCombinedRotationAngle, Space.World); break; case FaceDirection.Right: m_DummyTransform.Rotate(0, 0, -kCombinedRotationAngle, Space.World); break; } m_CombinedRotationTimer.Start(1.0f); } return(true); }
// Use this for initialization void Awake() { if (m_instance == null) { m_instance = this; } else { Destroy(this); } if (m_eventDatabase == null) { m_eventDatabase = new Dictionary <RoomWall, RoomUnityEvent>(); } m_rotationTick = new WaitForSeconds(Time.deltaTime); m_rotationRefresh = new UnityTimer(); m_rotationRefresh.Start(0); // make timer load up with 0 wait StartCoroutine(SetupRoom()); }