Пример #1
0
    public virtual void Update()
    {
        Vector2 input = _InputSource.GetMovementVector();

        if (controller.collisionInfo.below || controller.collisionInfo.above)
        {
            velocity.y = 0;
        }
        //if (controller.collisionInfo.left || controller.collisionInfo.right)
        //	velocity.x = 0;

        if (_InputSource.ShouldJump && IsGrounded)
        {
            velocity.y = JUMP_SPEED;
        }

        if ((input.x > 0 && !_isFacingRight) ||
            (input.x < 0 && _isFacingRight))
        {
            FlipDirection(input);
        }

        float targetVelocityX = input.x * MOVE_SPEED;

        velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, IsGrounded ? MOVE_ACCELERATION_TIME_GROUNDED : MOVE_ACCELERATION_TIME_AIRBORNE);

        velocity += GRAVITY * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }