Ejemplo n.º 1
0
        public void StartShake(CameraShakeProperties properties)
        {
            if (currentShakeCoroutine != null)
            {
                StopCoroutine(currentShakeCoroutine);
            }

            currentShakeCoroutine = Shake(properties);
            StartCoroutine(currentShakeCoroutine);
        }
Ejemplo n.º 2
0
        IEnumerator Shake(CameraShakeProperties properties)
        {
            float completionPercent = 0;
            float movePercent       = 0;

            float   angle_radians    = properties.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, properties.dampingPercent);
                    float noiseAngle    = (Random.value - .5f) * Mathf.PI;
                    angle_radians   += Mathf.PI + noiseAngle * properties.noisePercent;
                    currentWaypoint  = new Vector3(Mathf.Cos(angle_radians), Mathf.Sin(angle_radians)) * properties.strength * dampingFactor;
                    previousWaypoint = cam.localPosition;
                    moveDistance     = Vector3.Distance(currentWaypoint, previousWaypoint);

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

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

                    movePercent = 0;
                }

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


                yield return(null);
            } while (moveDistance > 0);
        }
Ejemplo n.º 3
0
 public void ShakeCamera(CameraShakeProperties properties)
 {
     StartShake(properties);
 }