Beispiel #1
0
    void Update()
    {
        if (!spline)
        {
            return;
        }

        EvaluateTimeLength();

        var splineAnimatorT = ConvertFrameToWarpedTime(BulletTime.frame, BulletTime.frameFraction, ref cacheWarpedTimeFrameNumber, ref cacheWarpedTime) + offSet + _additionalOffSet;
        var splineT         = ConvertWarpedTimeToSplineNormalizedParameter(splineAnimatorT);

        Vector3 newPos = spline.GetPositionOnSpline(splineT);

        newPos += _offs;
        newPos += Vector3.up * (offSetUp + _additionalOffSetUp);

        Quaternion qRot = spline.GetOrientationOnSpline(splineT);
        Vector3    tang = qRot * Vector3.right;

        float totalSway  = sway + _additionalSway;
        float swayNoise  = SwayNoise(swayFrequency);
        float swayAngle  = swayNoise * swayLeanAmplitude * Mathf.Min(totalSway, 1.0f);
        float swayOffSet = swayNoise * totalSway;

        newPos += (offSetSideways + _additionalOffSetSideways + swayOffSet) * tang;

        var splineTMinusEpsilon = ConvertWarpedTimeToSplineNormalizedParameter(splineAnimatorT - 0.01f);

        Quaternion qPast = spline.GetOrientationOnSpline(splineTMinusEpsilon);
        float      yrot  = qPast.eulerAngles.y;

        yrot = yrot - qRot.eulerAngles.y;

        yrot = yrot % 360;
        if (yrot > 180)
        {
            yrot = yrot - 360;
        }
        if (yrot < -180)
        {
            yrot = 360 + yrot;
        }

        var leanAngle = Mathf.Clamp(coolness * (yrot % 180) + swayAngle, -maxLeanAngle, maxLeanAngle);

        leanAngle = Mathf.Clamp(leanAngle + additionalLean % 180, -maxLeanAngle, maxLeanAngle);

        var realDeltaTime = (Time.timeScale < Mathf.Epsilon) ? (Time.deltaTime / Time.timeScale) : 0.1f;

        //	Keffo: Changed this to prevent the 'swimming' when scrubbing, seems to work.
        //	Original: _currLeanAngle = Mathf.Lerp(_currLeanAngle, leanAngle, BulletTime.isEditing ? 1.0f : 0.15f * 30f * realDeltaTime);
        if (BulletTime.isEditing || BulletTime.paused)
        {
            _currLeanAngle = leanAngle;
        }
        else
        {
            _currLeanAngle = Mathf.Lerp(_currLeanAngle, leanAngle, 0.15f * 30f * realDeltaTime);
        }

        Quaternion r = Quaternion.Euler(0.0f, 0.0f, _currLeanAngle);


        Vector3 steadyCamPos = newPos;

        if (!debug)
        {
            if (originOfLean)
            {
                var delta = originOfLean.transform.position - transform.position;
                delta  = Quaternion.Inverse(qRot) * delta;
                newPos = newPos + delta - r * delta;
            }

            transform.position = newPos;            //Vector3.Lerp(transform.position, newPos, BulletTime.deltaTime * 5.0f);
            transform.rotation = qRot * r;
        }

        if (leanAngle < -leanAngleToTriggerFx)
        {
            if (rightFx && !rightFx.IsAlive())
            {
                rightFx.Stop(true); rightFx.Play(true);
                var ra = BulletTime.RandomFromArray(rightAudio) as AudioSource;
                if (ra && ra.enabled == true)
                {
                    ra.Play();
                }
            }
        }
        if (leanAngle > leanAngleToTriggerFx)
        {
            if (leftFx && !leftFx.IsAlive())
            {
                leftFx.Stop(true); leftFx.Play(true);
                var la = BulletTime.RandomFromArray(leftAudio) as AudioSource;
                if (la && la.enabled == true)
                {
                    la.Play();
                }
            }
        }

        if (steadyCamRoot && !debug)
        {
            steadyCamRoot.transform.position = steadyCamPos;
            steadyCamRoot.transform.rotation = qRot;
        }

        if (onboardCamRoot)
        {
            if (legacyOnboardCamera)
            {
                onboardCamRoot.transform.position = newPos;
                onboardCamRoot.transform.rotation = qRot * r;
            }
            else
            {
                var frameXform = (originOfLean) ? originOfLean.transform : transform;
                onboardCamRoot.transform.position = frameXform.position;
                onboardCamRoot.transform.rotation = frameXform.rotation;
            }
        }
    }