Preventing parts from embedding into other things with a custom dragger

I’m making my own drag “tool”. It’s pretty simple – just setting the Primary Part of a model’s CFrame to Mouse.hit.p, with some extra stuff for rotation and whatnot.

The problem arises when the user starts rotating the part, or starts trying to place it against anything that isn’t down on the ground (like on the side of another part). The part then embeds itself halfway into whatever it’s being placed against.
The only past experience I’ve had with this kind of stuff is more rigid placement systems, where I can assume rotation to be negligible and that it’s only being placed around the ground. So based on this, I translate the CFrame of the dragged object by:
+ Vector3.new(0, CurrentDragTarget.PrimaryPart.Size.Y/2, 0)

Yet as one may expect, this only works for the ground and when the object isn’t actually rotated. If the object’s rotated, then Size.Y no longer serves as a measure for the size of the part going “up”. And if the object’s being placed horizontally against a part, well, then this just doesn’t work at all.

So my question is:
How do I prevent a part of variable rotation from embedding itself into the ground or into the sides of other parts when setting its CFrame to the mouse’s position?

I’ve exhausted the wiki and devforums (to my knowledge, at least) as well as external sources trying to look for a proper way to solve this and found nothing of use. I assume this can be solved with things such as the worldspace/objectspace CFrame functions or just a bit more complicated vector math, but I don’t know enough about these things (and the wiki doesn’t help enough) to properly use them to solve this particular issue.

1 Like

I’d potentially look into using this module by @AxisAngle

1 Like

Uhm, perhaps you could use MoveTo and then modify the model’s CFrame according to the rotation you have set?

Not sure if that’d work or not. Just a thought.

What you want is called a safe move. After rotating or when moving a part to the mouse’s hit CFrame, use :MoveTo(). This may mean making a temporary model to contain the selected part. Another option would be to use the Dragger service.

1 Like

Sheesh, can’t believe MoveTo() didn’t occur to me! My dragger is still… unpolished, but it’s now in a much more workable state.
Thanks a lot for the help. I appreciate it.