Beispiel #1
0
        private IEnumerator BoostOverrideCoroutine()
        {
            var endTime = Time.time + boostDuration;

            while (Time.time < endTime)
            {
                AirDriVRSystem.SetForce(new Vector2(0, -boostOverrideForceAmount), 10, AirDriVRSystem.OverrideMode.YOnly);
                yield return(null);
            }
        }
        private void Awake()
        {
            if (monitorMode == MonitorMode.Rigidbody && !rigidbody)
            {
                rigidbody = GetComponent <Rigidbody>();
            }
            accelBuffer  = new Vector3[accelBufferSampleCount];
            veloBuffer   = new Vector3[veloBufferSampleCount];
            gBuffer      = new Vector3[gBufferSampleCount];
            lastPosition = transform.position;

            if (updateAirDriVR)
            {
                if (!AirDriVRSystem.HasInitialized)
                {
                    updateAirDriVR = AirDriVRSystem.Init(airDriVRPort);
                }
                if (updateAirDriVR)
                {
                    AirDriVRSystem.SetHeadTransform(headTransform);
                }
            }
        }
        private void Calculate(float deltaTime)
        {
            // velo(smooth) -> acc(smooth) -> G(smooth) -> setForce by G
            if (monitorMode == MonitorMode.Transform)
            {
                var frameVelo = (transform.position - lastPosition) / deltaTime;

                veloBuffer[accelSamples % veloBufferSampleCount] = frameVelo;
                veloSamples++;

                velo = Vector3.zero;
                // SMOOTHING
                var veloCnt = Mathf.Min(veloSamples, veloBufferSampleCount);
                for (var i = 0; i < veloCnt; i++)
                {
                    velo += veloBuffer[i];
                }

                velo        /= veloCnt;
                lastPosition = transform.position;
            }

            var velocity   = (monitorMode == MonitorMode.Rigidbody) ? rigidbody.velocity : velo;
            var frameAccel = (velocity - lastVelocity) / deltaTime;

            accelBuffer[accelSamples % accelBufferSampleCount] = frameAccel;
            accelSamples++;

            accel = Vector3.zero;
            // SMOOTHING
            var cnt = Mathf.Min(accelSamples, accelBufferSampleCount);

            for (var i = 0; i < cnt; i++)
            {
                accel += accelBuffer[i];
            }

            accel /= cnt;
            if (transformModeGravity && monitorMode == MonitorMode.Transform)
            {
                accel += Physics.gravity;
            }

            gBuffer[gSamples % gBufferSampleCount] = Quaternion.Inverse(transform.rotation) * frameAccel / Physics.gravity.y;
            gSamples++;

            G = Vector3.zero;
            var gCnt = Mathf.Min(gSamples, gBufferSampleCount);

            for (var i = 0; i < gCnt; i++)
            {
                G += gBuffer[i];
            }

            G /= gCnt;

            if (updateAirDriVR)
            {
                AirDriVRSystem.SetForce(new Vector2(G.x / airDriVRMaxG, G.z / airDriVRMaxG), 0, overrideMode);
            }

            lastVelocity = velocity;
            lastRotation = transform.rotation;
        }