Example #1
0
        /// <summary>Get the current translational and rotational shake values taking all sources into account</summary>
        /// <returns>Offset and rotation as a structure</returns>
        public ShakeValue GetShake()
        {
            Vector2 totalTrauma = Vector2.zero;

            foreach (var pair in traumaSources)
            {
                Vector2 traumaValue = pair.Value;
                totalTrauma += traumaValue;
            }
            totalTrauma /= maxTrauma;
            if (totalTrauma.x > 1)
            {
                totalTrauma.x = 1;
            }
            if (totalTrauma.y > 1)
            {
                totalTrauma.y = 1;
            }

            Vector2 translationalIntensity = new Vector2(intensityCurve.Evaluate(totalTrauma.x), intensityCurve.Evaluate(totalTrauma.y));
            float   rotationalIntensity    = intensityCurve.Evaluate((totalTrauma.x + totalTrauma.y) / 2);

            if (rotationalIntensity < 0.001f)
            {
                return(new ShakeValue(Vector2.zero, 0));
            }

            float x = (Mathf.PerlinNoise(t, 0) * 2 - 1) * translationalIntensity.x * maxOffset;
            float y = (Mathf.PerlinNoise(0, t) * 2 - 1) * translationalIntensity.y * maxOffset;
            float r = (Mathf.PerlinNoise(t, t) * 2 - 1) * rotationalIntensity * maxRotation;

            return(new ShakeValue(new Vector2(x, y), r));
        }
Example #2
0
        /// <summary>
        /// Get the final movement target based on average of all target items
        /// </summary>
        /// <access>public override MovementTarget</access>
        /// <returns>A MovementTarget structure containing the target point and speed to move there</returns>
        public override MovementTarget GetMovementTarget()
        {
            Vector3 referencePosition;

            if (calculationMode == DistanceCalculationMode.RelativeToBaseTarget && baseFocalPoint != null)
            {
                referencePosition = baseFocalPoint.transform.position;
            }
            else
            {
                referencePosition = transform.position;
            }

            // Default values if no influence
            Vector3 finalPoint = transform.position;
            float   finalZoom = 1, finalPull = 0, finalSpeed = 1, totalWeight = 0;

            // Start with base values scaled by base weight
            if (baseFocalPoint != null)
            {
                finalPoint  = baseFocalPoint.transform.position * baseFocalPoint.weight;
                finalZoom   = baseFocalPoint.zoom * baseFocalPoint.weight;
                finalPull   = baseFocalPoint.pull * baseFocalPoint.weight;
                finalSpeed  = baseFocalPoint.speed * baseFocalPoint.weight;
                totalWeight = baseFocalPoint.weight;
            }

            // Sum targets based on weight and distance
            for (int i = 0; i < activeFocalPoints.Count; i++)
            {
                CameraFocalPoint target         = activeFocalPoints[i];
                Vector3          targetPosition = target.transform.position;
                if (target.weight > 0 && Vector2.SqrMagnitude(referencePosition - targetPosition) < target.maxDistance * target.maxDistance)
                {
                    float distance       = Vector2.Distance(target.transform.position, referencePosition);
                    float distanceScale  = distanceAttenuationCurve.Evaluate(distance / target.maxDistance);
                    float adjustedWeight = target.weight * target.influenceScale * distanceScale;
                    finalPoint  += target.transform.position * adjustedWeight;
                    finalZoom   += target.zoom * adjustedWeight;
                    finalPull   += target.pull * adjustedWeight;
                    finalSpeed  += target.speed * adjustedWeight;
                    totalWeight += adjustedWeight;
                }
            }

            // Get final point and speed values based on total weight
            finalPoint /= totalWeight;
            finalZoom  /= totalWeight;
            finalPull  /= totalWeight;
            finalSpeed /= totalWeight;

            return(new MovementTarget(finalPoint, finalZoom, finalPull, finalSpeed));
        }