private IEnumerator TransitionCutscene(float transitionTime, Room newRoom, RoomTransitionTrigger.Direction movementDirection) { float startTime = Time.time; float finishTime = startTime + transitionTime; Vector3 directionalVector = DirectionToVector(movementDirection); Vector3 camInitialPos = Camera.main.transform.position; bool isVertical = (directionalVector.x == 0); float cameraMoveDistance = isVertical ? cameraVerticalMoveDistance : cameraHorizontalMoveDistance; float transitionalDistance = isVertical ? verticalTransitionalDistance : horizontalTransitionalDistance; Vector3 camFinalPos = camInitialPos + directionalVector * cameraMoveDistance; cam.m_Follow = null; UpdateCameraBounds(globalBounds); playerStatus.Frozen = true; playerStatus.SetGravityEnabled(false); //playerStatus.CurrentState = PlayerStatus.State.Walk; playerStatus.SetVelocity((directionalVector * transitionalDistance) / roomTransitionTime); Debug.Log("Intended v: " + (directionalVector * transitionalDistance) / roomTransitionTime + ", actual v: " + playerStatus.GetComponent <Rigidbody2D> ().velocity); while (Time.time < finishTime) { cam.transform.position = Vector3.Lerp(camInitialPos, camFinalPos, (Time.time - startTime) / transitionTime); yield return(null); } Debug.Log("FINAL Intended v: " + (directionalVector * transitionalDistance) / roomTransitionTime + ", FINAL actual v: " + playerStatus.GetComponent <Rigidbody2D> ().velocity); EnterRoom(newRoom); cam.m_Follow = playerStatus.transform; playerStatus.Frozen = false; playerStatus.SetGravityEnabled(true); }
Vector2 DirectionToVector(RoomTransitionTrigger.Direction dir) { switch (dir) { case RoomTransitionTrigger.Direction.Left: return(Vector2.left); case RoomTransitionTrigger.Direction.Right: return(Vector2.right); case RoomTransitionTrigger.Direction.Up: return(Vector2.up); case RoomTransitionTrigger.Direction.Down: return(Vector2.down); default: Debug.LogWarning("Direction to vector method called with no valid direction??"); return(Vector2.zero); } }