Exemplo n.º 1
0
    private void Start()
    {
        GameInstance.GameState.OnPausedChanged += OnPause;

        cameraShakeSettings = new CameraShakeSettings
        {
            initialPosition    = cameraPivot.localPosition,
            initialRotation    = cameraPivot.localRotation.eulerAngles,
            initialFieldOfView = cam.fieldOfView
        };

        if (explosionShake == null)
        {
            explosionShake = new CameraShake(1f, 0.1f, 0.4f);

            explosionShake.fieldOfViewShake = new CameraShake.ElementShake(0.3f, 2f);

            explosionShake.positionShake[0] = new CameraShake.ElementShake(0.1f, 2f);
            explosionShake.positionShake[1] = new CameraShake.ElementShake(0.1f, 2f);
            explosionShake.positionShake[2] = new CameraShake.ElementShake(0.1f, 2f);

            explosionShake.rotationShake[0] = new CameraShake.ElementShake(0.1f, 2f);
            explosionShake.rotationShake[1] = new CameraShake.ElementShake(0.1f, 2f);
            explosionShake.rotationShake[2] = new CameraShake.ElementShake(0.1f, 2f);
        }

        InvokeRepeating("UpdateInteraction", 0f, 0.15f);
    }
Exemplo n.º 2
0
    public void StartShake(CameraShakeSettings properties)
    {
        if (currentShakeCoroutine != null)
        {
            StopCoroutine(currentShakeCoroutine);
        }

        currentShakeCoroutine = Shake(properties);
        StartCoroutine(currentShakeCoroutine);
    }
Exemplo n.º 3
0
    public void DoShake(CameraShakeSettings settings)
    {
        var startingIntensity = Math.Abs(_currentIntensity) < 0.01f ? 0f : _currentIntensity;
        if (isShakeRunning)
        {
            StopCoroutine(_currentShake);
            startingIntensity += settings.ShakeIntensity* settings.MitigationOnShakeAddition;
            isShakeRunning = false;
        }
        else
        {
            _originalPosition = transform.position;
        }

        _currentShake = ProcessShake(settings.ShakeIntensity, startingIntensity + settings.ShakeIntensity, settings.ShakeTime);
        StartCoroutine(_currentShake);
    }
Exemplo n.º 4
0
    public void DoShake(CameraShakeSettings settings)
    {
        var startingIntensity = Math.Abs(_currentIntensity) < 0.01f ? 0f : _currentIntensity;

        if (isShakeRunning)
        {
            StopCoroutine(_currentShake);
            startingIntensity += settings.ShakeIntensity * settings.MitigationOnShakeAddition;
            isShakeRunning     = false;
        }
        else
        {
            _originalPosition = transform.position;
        }

        _currentShake = ProcessShake(settings.ShakeIntensity, startingIntensity + settings.ShakeIntensity, settings.ShakeTime);
        StartCoroutine(_currentShake);
    }
Exemplo n.º 5
0
    IEnumerator Shake(CameraShakeSettings settings)
    {
        float completionPercent = 0;
        float movePercent       = 0;

        float   angle_radians    = settings.angle * Mathf.Deg2Rad - Mathf.PI;
        Vector3 previousWaypoint = Vector3.zero;
        Vector3 currentWaypoint  = Vector3.zero;
        float   moveDistance     = 0;
        float   speed            = 0;

        Quaternion targetRotation   = Quaternion.identity;
        Quaternion previousRotation = Quaternion.identity;

        do
        {
            if (movePercent >= 1 || completionPercent == 0)
            {
                float dampingFactor = DampingCurve(completionPercent, settings.dampingPercent);
                float noiseAngle    = (Random.value - .5f) * Mathf.PI;
                angle_radians  += Mathf.PI + noiseAngle * settings.noisePercent;
                currentWaypoint = new Vector3(Mathf.Cos(angle_radians), Mathf.Sin(angle_radians)) *
                                  settings.strength * dampingFactor;
                previousWaypoint = transform.localPosition;
                moveDistance     = Vector3.Distance(currentWaypoint, previousWaypoint);

                targetRotation = Quaternion.Euler(new Vector3(currentWaypoint.y, currentWaypoint.x).normalized *
                                                  settings.rotationPercent *dampingFactor *maxAngle);
                previousRotation = transform.localRotation;

                speed = Mathf.Lerp(settings.minSpeed, settings.maxSpeed, dampingFactor);

                movePercent = 0;
            }

            completionPercent      += Time.deltaTime / settings.duration;
            movePercent            += Time.deltaTime / moveDistance * speed;
            transform.localPosition = Vector3.Lerp(previousWaypoint, currentWaypoint, movePercent);
            transform.localRotation = Quaternion.Slerp(previousRotation, targetRotation, movePercent);


            yield return(null);
        } while (moveDistance > 0);
    }