Пример #1
0
        /// <summary>
        /// Updates the distance travelled and checks if footstep events need to be fired
        /// </summary>
        public void Tick()
        {
            var currentPosition = m_Transform.position;

            //If the character has not moved or is not grounded then ignore the calculations that follow
            if (currentPosition == m_PreviousPosition || !brain.controllerAdapter.isGrounded)
            {
                m_PreviousPosition = currentPosition;
                return;
            }

            m_SqrTravelledDistance += (currentPosition - m_PreviousPosition).sqrMagnitude;

            if (m_SqrTravelledDistance >= m_SqrDistanceThreshold)
            {
                m_SqrTravelledDistance = 0;
                var data =
                    new MovementEventData(m_Transform, Mathf.Clamp01(brain.planarSpeed / m_MaximumSpeed));
                PlayFootstep(data);

                m_IsLeftFoot = !m_IsLeftFoot;
            }

            m_PreviousPosition = currentPosition;
        }
Пример #2
0
		/// <summary>
		/// Plays the particles and scales them based on magnitude
		/// </summary>
		/// <param name="movementEventData">The data driving the movement event</param>
		/// <param name="effectMagnitude">The magnitude of the effect used for scaling the particle system size</param>
		protected override void PlayMovementEvent(MovementEventData movementEventData, float effectMagnitude)
		{
			var scale = Vector3.one * effectMagnitude;
			foreach (var particleSystem in m_ParticleSystems)
			{
				particleSystem.transform.localScale = scale;
				particleSystem.Play();
			}
		}
Пример #3
0
    public void OnMovedOnGround(MovementEventData eventData)
    {
        if (!m_EnabledInEditor || !enabled || m_HopSequence.Active)
        {
            return;
        }

        Hop(eventData.m_NormalizedDelta);
    }
Пример #4
0
        /// <summary>
        /// Plays the movement event at a set location
        /// </summary>
        /// <param name="movementEventData"></param>
        public void Play(MovementEventData movementEventData)
        {
            if (movementEventData.firedFrom != null)
            {
                transform.position = movementEventData.firedFrom.position;
                if (m_SetRotation)
                {
                    transform.rotation = movementEventData.firedFrom.rotation;
                }
            }

            PlayMovementEvent(movementEventData);
        }
Пример #5
0
        // Handles footstep effects
        void PlayFootstep(MovementEventData movementEventData)
        {
            CheckArea();
            if (m_IsLeftFoot)
            {
                PlayLeftFoot(movementEventData);
            }
            else
            {
                PlayRightFoot(movementEventData);
            }

            m_IsLeftFoot = !m_IsLeftFoot;
        }
Пример #6
0
    public void Move(float input)
    {
        if (!enabled)
        {
            return;
        }

        if (m_Boosting)
        {
            if (m_BoostTimer >= m_LatestBoostDelay)
            {
                // "Input alignment" is basically the 1D dot product of the X velocity
                // and the movement input
                var xVelocity      = m_Rigidbody.velocity.x;
                var inputAlignment = xVelocity * input;

                if (inputAlignment < 0)
                {
                    EndBoosting();
                }
            }
        }
        else // if not boosting
        {
            var velocity = m_Rigidbody.velocity;
            velocity.x           = input * m_MovementSpeed;
            m_Rigidbody.velocity = velocity;

            if (Mathf.Abs(input) > 0)
            {
                var deltaX          = m_Transform.position.x - m_PreviousX;
                var currentSpeed    = deltaX / Time.deltaTime;
                var normalizedDelta = currentSpeed / m_MovementSpeed;

                var eventData = new MovementEventData()
                {
                    m_NormalizedDelta = normalizedDelta,
                };

                m_Events.Moved.Invoke(eventData);

                if (m_Grounded)
                {
                    m_Events.MovedOnGround.Invoke(eventData);
                }
            }

            m_PreviousX = m_Transform.position.x;
        }
    }
        /// <summary>
        /// Selects an audio clip (by cycling through them) and changes the volume based on <paramref name="effectMagnitude"/>
        /// </summary>
        /// <param name="movementEventData">The <see cref="MovementEventData"/> data</param>
        /// <param name="effectMagnitude">The magnitude of the effect</param>
        protected override void PlayMovementEvent(MovementEventData movementEventData, float effectMagnitude)
        {
            if (m_Source == null)
            {
                return;
            }

            if (m_Clips.Length != 0)
            {
                if (m_CurrentSoundIndex >= m_Clips.Length)
                {
                    m_CurrentSoundIndex = 0;
                }
                m_Source.PlayOneShot(m_Clips[m_CurrentSoundIndex++], effectMagnitude);
                return;
            }

            m_Source.volume = effectMagnitude;
            m_Source.Play();
        }
 // Plays the right foot movement events
 //      movementEventData: the data need to play the event
 //      physicMaterial: physic material of the footstep
 void HandleRightFoot(MovementEventData movementEventData, PhysicMaterial physicMaterial)
 {
     SetPhysicMaterial(physicMaterial);
     movementEventData.normalizedSpeed = Mathf.Clamp01(m_ThirdPersonBrain.planarSpeed / m_MaximumSpeed);
     PlayRightFoot(movementEventData);
 }
Пример #9
0
 /// <summary>
 /// Plays the event using the effectMagnitude
 /// </summary>
 /// <param name="movementEventData">The current <see cref="MovementEventData"/> to be played</param>
 /// <param name="effectMagnitude">The magnitude of the effect - this is the actual value and not a normalized value</param>
 protected abstract void PlayMovementEvent(MovementEventData movementEventData, float effectMagnitude);
Пример #10
0
        /// <summary>
        /// Intercepts the movement event call, calculates and appends the effect magnitude
        /// </summary>
        /// <param name="movementEventData">The <see cref="MovementEventData"/> that is intercepted</param>
        protected void PlayMovementEvent(MovementEventData movementEventData)
        {
            var effectMagnitude = Evaluate(movementEventData.normalizedSpeed);

            PlayMovementEvent(movementEventData, effectMagnitude);
        }