Exemplo n.º 1
0
        private void FixedUpdate()
        {
            HandPenetration deepestPenetrator = GetDeepestPenetrator();

            audioSource.volume = (deepestPenetrator.MaxPenetrationDepth * depthVolumeBoost) * (IsGraspingObject() ? 0 : 1);
            if (Mathf.Approximately(audioSource.volume, 0) && audioSource.isPlaying)
            {
                audioSource.Pause();                                                                                  // don't waste CPU time playing nothing
            }
            else
            {
                audioSource.UnPause();
            }

            // move audiosource to center of all penetrating bodies
            int     penetratorCount  = 0;
            Vector3 penetratorCenter = GetPenetratorCenter(out penetratorCount);

            audioSource.transform.position = penetratorCenter;

            if (!overridePenetrationHaptics.GetValue())
            {
                CalculatePenetrationHaptics(penetratorCount > 0 ? deepestPenetrator : null);
            }
            if (doHaptics)
            {
                HapticUpdate();
            }
        }
Exemplo n.º 2
0
        private HandPenetration GetDeepestPenetrator()
        {
            HandPenetration deepestPenetrator = penetrators[0];

            for (int i = 0; i < penetrators.Length; i++)
            {
                if (penetrators[i].MaxPenetrationDepth > deepestPenetrator.MaxPenetrationDepth)
                {
                    deepestPenetrator = penetrators[i];
                }
            }

            return(deepestPenetrator);
        }
Exemplo n.º 3
0
        private void CalculatePenetrationHaptics(HandPenetration deepestPenetrator)
        {
            if (deepestPenetrator == null)
            {
                doHaptics = false;
                return;
            }

            currentDeepestPenetration = deepestPenetrator.MaxPenetrationDepth;

            float depthTValue = Mathf.InverseLerp(0, penetrationHapticsMaxout, deepestPenetrator.MaxPenetrationDepth);

            amplitude = Mathf.Lerp(0, 1, depthTValue) * GetGrabVolumeMultiplier();
            frequency = Mathf.Lerp(1, 40, depthTValue);
            doHaptics = true;
        }