What would be the best way to implement a drag and drop system that snaps the dragged rectangle to the edges of other rectangles? I’ve already got the basic drag and drop code made. Also, none of the rectangles are rotated. Thanks in advance!
As part of your current drag system, you presumably have some place in your code that you update the object’s position based on the location of the drag.
You have to add a step where you check if the position you are about to set is close enough to any legal snap target that you want it to snap, and if so, modify the position to be in alignment. (You might-or-might-not want to snap each axis independently, depending on what result you want.)
That implies you’ll need to know what things you can potentially snap to; how to determine that will depend on your context. For example, it may involve iterating over a list of other rectangles in your scene that you might potentially want to snap to.
Please don’t make duplicate threads.
https://forum.unity.com/threads/rectangle-snapping-system.764597/
Oops, sorry. I realized that that thread was a bit of a mouthful, so I rewrote it here. Should I delete that other thread?
Thanks! I’ll give that a shot.
I’m not sure you can delete it so don’t worry about it, but you can edit threads in the future rather than making a new one.