void Start() { Debug.Assert(CameraPlaces.Count > 0); transform.position = CameraPlaces[0].position.position; //Goes to both the start and rotation position transform.LookAt(CameraPlaces[0].target.position); _stayTimer = CameraPlaces[0].Duration; //Timers _transitionTimer = CameraPlaces[0].TransitionDuration; CurrentCamTarget = CameraPlaces[0]; }
void Update() { Debug.Assert(CameraPlaces.Count > 0); if (finished) { return; } if (_isTransitioning) { // update the transition timer _transitionTimer -= Time.deltaTime; // calculate the new position and rotation smoothly interpolated var curr = getPrevTarget(); var next = getCurrentTarget(); // 0...1 value over the transition time float t = 1.0f - (_transitionTimer / curr.TransitionDuration); // position and rotation update based on current and previous views transform.position = smoothstepVec3(curr.position.position, next.position.position, t); transform.rotation = Quaternion.LookRotation(smoothstepVec3(curr.direction(), next.direction(), t)); // check whether we need to change state and reset the timer if (_transitionTimer < 0.0f) { _transitionTimer = curr.TransitionDuration; _isTransitioning = false; } } else { // update the stay timer _stayTimer -= Time.deltaTime; // check whether we need to change state and reset the timer if (_stayTimer < 0.0f) { _isTransitioning = true; _previousIndex = _currentIndex; _currentIndex = (_currentIndex + 1); if (_currentIndex >= CameraPlaces.Count) { finished = true; } else { CurrentCamTarget = CameraPlaces[_currentIndex]; _stayTimer = CurrentCamTarget.Duration; } } // just stay; don't do anything } }
void Start() { Debug.Assert(CameraPlaces.Count > 0); // go to start position and rotation transform.position = CameraPlaces[0].position.position; transform.LookAt(CameraPlaces[0].target.position); // initialize timers _stayTimer = CameraPlaces[0].Duration; _transitionTimer = CameraPlaces[0].TransitionDuration; CurrentCamTarget = CameraPlaces[0]; }
void Update() { Debug.Assert(CameraPlaces.Count > 0); if (finished) { return; } if (_isTransitioning) { _transitionTimer -= Time.deltaTime; //Updates the transition timer on the camera var curr = getPrevTarget(); //The updated positions/rotations are smoothed for cameras var next = getCurrentTarget(); float t = 1.0f - (_transitionTimer / curr.TransitionDuration); transform.position = smoothstepVec3(curr.position.position, next.position.position, t); transform.rotation = Quaternion.LookRotation(smoothstepVec3(curr.direction(), next.direction(), t)); if (_transitionTimer < 0.0f) { _transitionTimer = curr.TransitionDuration; _isTransitioning = false; } } else { _stayTimer -= Time.deltaTime; if (_stayTimer < 0.0f) { _isTransitioning = true; _previousIndex = _currentIndex; _currentIndex = (_currentIndex + 1); if (_currentIndex >= CameraPlaces.Count) { finished = true; } else { CurrentCamTarget = CameraPlaces[_currentIndex]; _stayTimer = CurrentCamTarget.Duration; } } } }