Esempio n. 1
0
        /// <summary>
        /// Detect the footstep.
        /// </summary>
        private void FixedUpdate()
        {
            if (m_FootstepMode == FootstepPlacementMode.None)
            {
                return;
            }

#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
            if (m_NetworkInfo != null && !m_NetworkInfo.IsLocalPlayer())
            {
                var velocity = (m_PreviousPosition - m_Transform.position) / Time.deltaTime;
                m_PreviousPosition = m_Transform.position;

                var localVelocity = m_Transform.InverseTransformDirection(velocity);
                localVelocity.y = 0;
                // The character has to be moving in order to place a footstep.
                if (localVelocity.sqrMagnitude <= 0.1f)
                {
                    return;
                }

                // The character should be grounded.
                RaycastHit raycastHit = new RaycastHit();
                if (!m_CharacterLocomotion.SingleCast(-m_Transform.up * (m_CharacterLocomotion.SkinWidth + m_CharacterLocomotion.ColliderSpacing), Vector3.zero, m_CharacterLayerManager.SolidObjectLayers, ref raycastHit))
                {
                    return;
                }
            }
            else
            {
#endif
            // The character has to be grounded and moving in order to be able to place footsteps.
            if (!m_CharacterLocomotion.Grounded || !m_CharacterLocomotion.Moving)
            {
                return;
            }
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
        }
#endif

            switch (m_FootstepMode)
            {
            case FootstepPlacementMode.BodyStep:
                DetectBodyStep();
                break;

            case FootstepPlacementMode.FixedInterval:
                UpdateFixedInterval();
                break;

            case FootstepPlacementMode.CameraBob:
                DetectCameraBob();
                break;
            }
        }