✓ Accepted answer
result preview
Yes. Check if the mouse's position is within a certain magnitude. I used a collection of these frames in my GIF. Firstly, when the user stops dragging the frame, it sorts the collection of frames by which is closer to the Mouse's position.
do
local mousePos = Vector2.new(input.Position.X, input.Position.Y)
table.sort(frames, function(f1, f2)
local f1Pos = f1.AbsolutePosition + f1.AbsoluteSize / 2
local f2Pos = f2.AbsolutePosition + f2.AbsoluteSize / 2
return (mousePos - f1Pos).Magnitude < (mousePos - f2Pos).Magnitude
end)
end
'frames' is the table of frames (frameCollection:GetChildren()) which is sorted after that algorithm. frames[1] is the closest frame to the mouse. You then should be able to assign the marker frame to the closest frame (frame[1]), like so:
marker.Position = UDim2.new(0, frames[1].AbsolutePosition.X, 0, frames[1].AbsolutePosition.Y)
To actually move the marker, I connected a function to RenderStepped which checks for dragging (boolean). If true then move the marker to the Mouse's position.
If you're wondering, here is the hierarchy of the Gui.
and here is the full Model in case you want it for further study
Hope it helped!
1 comment
Here is the source code: https://pastebin.com/AM4pAPuc - sorry about the lack of documentation.