private void SetParameters(AnimatedMotorProperties input)
        {
            if (_animator == null || _animator.runtimeAnimatorController == null)
            {
                return;
            }

            _animator.SetFloat(SpeedPercent, input.MoveSpeedNormalized, dampTime, Time.deltaTime);

            foreach (var parameter in _animator.parameters)
            {
                var nameHash = parameter.nameHash;
                if (nameHash == InAir)
                {
                    _animator.SetBool(InAir, !input.IsGrounded);
                }
                else if (nameHash == DirectionY)
                {
                    _animator.SetFloat(DirectionY, input.DirectionY, dampTime, Time.deltaTime);
                }
                else if (nameHash == VelocityX)
                {
                    _animator.SetFloat(VelocityX, input.VelocityX, dampTime, Time.deltaTime);
                }
                else if (nameHash == VelocityZ)
                {
                    _animator.SetFloat(VelocityZ, input.VelocityZ, dampTime, Time.deltaTime);
                }
                else if (nameHash == InHitStun)
                {
                    _animator.SetBool(InHitStun, input.IsHitReacting);
                }
            }
        }
Esempio n. 2
0
        public void AfterCharacterUpdate(float deltaTime)
        {
            // Handle jump-related values
            {
                // Handle jumping pre-ground grace period
                if (_jumpRequested && _timeSinceJumpRequested > JumpPreGroundingGraceTime)
                {
                    _jumpRequested = false;
                }

                // Handle jumping while sliding
                if (AllowJumpingWhenSliding ? Motor.GroundingStatus.FoundAnyGround : Motor.GroundingStatus.IsStableOnGround)
                {
                    // If we're on a ground surface, reset jumping values
                    if (!_jumpedThisFrame)
                    {
                        _jumpConsumed = false;
                    }
                    _timeSinceLastAbleToJump = 0f;
                }
                else
                {
                    // Keep track of time since we were last able to jump (for grace period)
                    _timeSinceLastAbleToJump += deltaTime;
                }
            }

            var input = new AnimatedMotorProperties()
            {
                MoveSpeedNormalized = Motor.BaseVelocity.magnitude / RunSpeed,
                IsGrounded          = Motor.GroundingStatus.FoundAnyGround,
                DirectionY          = Mathf.Clamp01(Mathf.InverseLerp(1f, -1f, Motor.Velocity.y)),
                VelocityX           = Vector3.Dot(Motor.BaseVelocity, Motor.CharacterRight) / RunSpeed,
                VelocityZ           = Vector3.Dot(Motor.BaseVelocity, Motor.CharacterForward) / RunSpeed,
                IsHitReacting       = _isHitReacting
            };

            OnAnimatedPropertiesChanged?.Invoke(input);
        }