How to make gui object draggable w/ auto snap

Assume theres a gui object at 0, 200, 0, 200.
(Container: Size - 1, -18, 1, -9; Position - 0.5 (center*),0,0,0)
if I want to make the object draggable,
as well as align them if close to the edges (10px) (for example bottom right: 1,0,1,0 anchor 1,1)

how do I create that?

2 Likes

When someone clicks the GUI, remember the offset between their mouse and the GUI’s absolute position. As long as they hold the mouse, adjust the position so that the offset stays the same. To add snapping, you need to calculate the difference between each edge you want to have snapping, and valid places to snap it. If less than some threshold, choose that position for that axis instead of the constant offset above. Probably you want to do the X and Y axis separately, so that you can snap to one edge or into a corner.

2 Likes

ik for that but not if UIScale :sweat_smile:
my calculations got messy and completely break if not 1x

If you calculate based on AbsoluteSize and AbsolutePosition that should account for scale.