public IEnumerator MoveCameraXAxis(Vector3 destination)
    {
        Vector3 cameraStartPosition = transform.position;
        float   currentTime         = 0;

        while (currentTime < cameraAnimationTime)
        {
            currentTime       += Time.deltaTime;
            transform.position = new Vector3(Mathf.Lerp(cameraStartPosition.x, destination.x, currentTime / cameraAnimationTime), cameraStartPosition.y, cameraStartPosition.z);
            yield return(new WaitForEndOfFrame());
        }
        OnCameraMoved?.Invoke(this, EventArgs.Empty);
        OnCameraMoved = delegate { };
    }
Example #2
0
    private void LateUpdate()
    {
        if (PlayerController.PlayerCurrentState == PlayerController.PlayerState.Interacting)
        {
            return;
        }

        float distanceToCamp = Vector3.Distance(new Vector3(500, 0, 520), PlayerController.PlayerPosition);

        if (distanceToCamp < _campSnapDistance)
        {
            OnCameraOnCamp?.Invoke();
            // Camera position
            transform.position = new Vector3(497.9f, 21.1f, 496.2f);
        }
        else
        {
            Vector2 targetScreenSpace = _mainCamera.WorldToScreenPoint(PlayerController.PlayerPosition);
            targetScreenSpace = _mainCamera.ScreenToViewportPoint(targetScreenSpace);
            float distanceToCenter = Vector2.Distance(new Vector2(0.5f, 0.5f), targetScreenSpace);

            _canFollow = distanceToCenter > _invalidBound;

            if (distanceToCenter > 1)
            {
                //reset
                _movementOffset = _offset;

                transform.position = PlayerController.PlayerPosition + _movementOffset;
            }

            if (!_canFollow)
            {
                return;
            }

            transform.position = PlayerController.PlayerPosition + _offset;


            OnCameraMoved?.Invoke();
        }
    }