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.