Пример #1
0
        public void FixedUpdate()
        {
            float   horizontalInput = Input.GetAxis("Horizontal");
            Vector2 horizontalForce = new Vector2(horizontalInput * MovementMultiplier, 0f);

            BehaviorManager.Rb.AddForce(horizontalForce);
            float clampedHorzVel = Mathf.Clamp(BehaviorManager.Rb.velocity.x, -MaxHorizontalVelocity, MaxHorizontalVelocity);

            BehaviorManager.Rb.velocity = new Vector2(clampedHorzVel, BehaviorManager.Rb.velocity.y);

            _animator.SetFloat(HorizontalSpeedAbsoluteId, Mathf.Abs(BehaviorManager.Rb.velocity.x));

            //check to see if should call flip method which will call OnFlip() on all activated behaviors
            if (horizontalInput < 0 && wasFacingRight == true)
            {
                BehaviorManager.Flip();
                wasFacingRight = false;
            }

            if (horizontalInput > 0 && wasFacingRight == false)
            {
                BehaviorManager.Flip();
                wasFacingRight = true;
            }
        }