I want to create a system where you could drag items and move or rotate them, ideally close to what the select tool in studio does, but without visible snapping. My first thought was doing something like this:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Part = Instance.new("Part",workspace)
Mouse.TargetFilter = Part
game:GetService("RunService").RenderStepped:Connect(function()
Part.Position = Mouse.Hit.p
end)
But then, when my mouse points at the baseplate, the part gets halfway stuck, like this:
Then, I thought about adding half the height of the part to compensate.
Part.Position = Mouse.Hit.p + Vector3.new(0,Part.Size.Y,0)
Result:
As you can see, it doesn’t get stuck in the ground anymore. But, what about other sides? This could happen in a room:
As you can see, the part also gets stuck, but not on the y-axis, but rather on the x- and z- axes.
How do I determine how much to move back, on which axes?
i’d say either raycasting or :GetTouchingParts(), but can’t really think of how to do it exactly
And then there are models, which can be oddly shaped! Should I move them accordingly using Model:GetBoundingBox()
?
Thanks in advance!
yes i’ve grinded google for about 14 hours but i couldn’t find any that does this easily