Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        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;
        }