Drag preview and drop positioning

Godot Version

4.3

Question

I’m using Godot’s built in drag and drop system but I’m having trouble with positioning the objects when they’re being dragged and when they’re dropped.

First, when I drag the card, it grabs it by the top left corner and I want to drag it by the center.

Second, for demonstration purposes, the Godot logos represent the “slots” where the cards can be dropped. When I drop them, they attach to the slots at the top left corner instead of the center. How can I get them to drag at the center and drop in the center of the slot?

Because Control position is based on the rect system (the top-left position and the control size), when you get the control position, will be always the top-left position, if you want the control center just add the half of the control size:

var my_control_center_pos = global_position + get_rect().size/2

In these cases I usually add a 1x1 Pixel control as parent of the actual preview-Control and center it on the 1x1 Pixel control.