Ejemplo n.º 1
0
    public override void _PhysicsProcess(float delta)
    {
        Vector2 axis = _joystick.GetValue().Normalized();

        if (axis == Vector2.Zero)
        {
            // Not moving
            ApplyFriction(_Acceleration * delta);
        }
        else
        {
            //Moving
            ApplyMovement(axis * _Acceleration * delta);

            bool vertical = Mathf.Abs(axis.y) > Mathf.Abs(axis.x);
            bool positive = Mathf.Sign(vertical ? axis.y : axis.x) > 0f;

            PlayerDirection = vertical ? (positive ? Direction.Down : Direction.Up) : (positive ? Direction.Right : Direction.Left);
        }

        _motion = MoveAndSlide(_motion);

        if (_motion.Length() > 0f)
        {
            _playerIsMoving = true;
        }
        else
        {
            _playerIsMoving     = false;
            _playerSprite.Frame = 0;
        }

        ZIndex = Mathf.FloorToInt(Position.y + 15f);
    }
Ejemplo n.º 2
0
    public override void _Process(float delta)
    {
        Vector2 axis = _joystick.GetValue();

        Position += axis * delta * _moveSpeed;
    }