コード例 #1
0
        private IEnumerator RoutineMonitorTilt()
        {
            float tiltLowVelocity  = 0f;
            float tiltHighVelocity = 0f;

            WaitForEndOfFrame waitHandle = new WaitForEndOfFrame();

            yield return(waitHandle);

            while (true)
            {
                // Adapt the operating tilt range based on the operating height range, and if it's
                // over its limits, then move it towards it's target range.
                float t = operatingHeightRange.InverseLerp(CurrentHeight);
                t = Mathf.Clamp01(t);
                t = settings.EvaluateTiltTransition(t);
                ValueRange targetRange = ValueRange.Lerp(settings.TiltRangeLow, settings.TiltRangeHigh, t);
                operatingTiltRange.Set(
                    Mathf.SmoothDampAngle(operatingTiltRange.Min, targetRange.Min, ref tiltLowVelocity, 0.2f),
                    Mathf.SmoothDampAngle(operatingTiltRange.Max, targetRange.Max, ref tiltHighVelocity, 0.2f));

                ApplyTiltFactor();
                yield return(waitHandle);
            }
        }
コード例 #2
0
        private void UpdateOperatingHeightRange(Vector3 origin)
        {
            float targetMin = settings.AbsoluteHeightRange.Min;
            float targetMax = settings.AbsoluteHeightRange.Max;

            // Define a possibly height operational minimum.
            if (Physics.Raycast(origin, Vector3.down, out RaycastHit minHit, settings.AbsoluteHeightRange.Range, settings.InteractionMask))
            {
                targetMin = Mathf.Max(minHit.point.y, targetMin);
            }

            // Define a possibly lower operational maximum. This one will most likely
            // never occur, unless we enter some kind of cave or structure with overhanging objects.
            if (Physics.Raycast(origin, Vector3.up, out RaycastHit maxHit, settings.AbsoluteHeightRange.Range, settings.InteractionMask))
            {
                targetMax = Mathf.Min(maxHit.point.y, targetMax);
            }

            operatingHeightRange.Set(targetMin, targetMax);
        }
コード例 #3
0
 private void OnValidate()
 {
     // For reasons axis-flipping reasons, the tilt ranges should remain within the -90 to 90 degrees range.
     tiltRangeHigh.Set(Mathf.Clamp(tiltRangeHigh.Min, -90f, 90f), Mathf.Clamp(tiltRangeHigh.Max, -90f, 90f));
     tiltRangeLow.Set(Mathf.Clamp(tiltRangeLow.Min, -90f, 90f), Mathf.Clamp(tiltRangeLow.Max, -90f, 90f));
 }