Most efficient way to make a part-dragging system?

So what I’m trying to do right now is create a system where you can click a part, and drag it around. Basically a re-creation of the system that Work at a Pizza Place uses for supply boxes.


As shown, you click a part, move it around by moving your mouse.

As I showed in the gif, if the part would intersect with another part, it will be automatically moved so it doesn’t intersect with that part.

I’m currently theorizing the best way to go about accomplishing this. I could easily raycast towards the middle of the part, and to every corner, and that would accomplish what I want. The issue with this is that there are certain cases where there is a tiny part in-between those raycasts, therefore avoiding detection. A solution to avoid that issue would be to spam raycasts, but that doesn’t seem very efficient to me. I was also looking into Region3 options but realized there are issues there that would also make it inefficient.

I’m wondering if anyone knows an efficient solution to this problem. At the end of the day I’m fine using a couple extra raycasts as a backup solution, but it just feels wrong to be inefficient when I know there is a better way out there.

I hope I don’t sound blunt here, but you should try it and see if you run into performance problems. And if so, go from there.

I’ve done a lot of crazy stuff with raycasting, and actually still do, and haven’t came across any major performance issues. As long as you aren’t running this 60 times per second (and even then it might still be okay) I’d think your current solution would be fine.

1 Like

Alright, I’ll go for it and see what happens!

1 Like