Exemplo n.º 1
0
    public override void _PhysicsProcess(float delta)
    {
        Vector2 axisInput = new Vector2(0.0f, 0.0f);

        foreach (AxisMapping axisMapping in _axisMappings)
        {
            if (Input.IsActionPressed(axisMapping.ActionName))
            {
                axisInput += axisMapping.Axis;
            }
        }

        axisInput = axisInput.Normalized();
        Vector2 velocity = axisInput * WalkSpeed;
        KinematicCollision2D collision = MoveAndCollide(velocity * delta);

        if (collision != null)
        {
            Node2D collider = collision.Collider as Node2D;
            if (collider != null && collider.IsInGroup("pushable"))
            {
                IPushable pushedObject = collider as IPushable;
                pushedObject?.TryPush(collision.Normal, delta);
            }

            velocity = velocity.Slide(collision.Normal);
            MoveAndCollide(velocity * delta);
        }
    }