Move Part With Mouse Tool not working correctly, Part clips halfway into other parts

Hey, so I know this question has been asked a million times, but I haven’t been able to get a concrete solution to this problem.

This move tool is supposed to move the part to where ever the mouse is, however it seems to not collide with other parts. Here is my code:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Move = Instance.new("Tool", Player.Backpack)
local md = false
local target
local opticalpart
Move.Name = "Move"
Move.RequiresHandle = false

Move.Equipped:Connect(function(m)
	m.Button1Down:Connect(function()
		if Mouse.Target ~= nil then
			target = Mouse.Target
			opticalpart = target:Clone()
			opticalpart.Transparency = .5
			opticalpart.CanCollide = true
			opticalpart.Parent = workspace
			Mouse.TargetFilter = opticalpart
			md = true
			Mouse.Move:Connect(function()
				if md == true and target ~= nil and opticalpart ~= nil then
					opticalpart.Position = Mouse.Hit.Position
				end
			end)
		end
	end)
	m.Button1Up:Connect(function()
		md = false
	end)
end)

Here is a visual of the issue I’m having:

As you can see, the part is clipping through the floor and even with other parts.

Before you say “Use BodyPosition”, “Use the Dragger Instance”. I tried those, and it did not suit what I want to accomplish. BodyPosition requires the part to be unanchored (which I don’t want), and it moves in a delayed way that I don’t like. The dragger instance does fix the problem somewhat, but it moves in increments, and has problems in small spaces.

I just want to be able to move this part with the mouse without it being unanchored or moving choppy.
Thank you!

Is it possible that the part is anchored after the dragging is finished? As for being late, perhaps use AlignPosition instead with RigidityEnabled being true.

You need to offset the part by half of its height so that it doesn’t clip into the floor.

If you don’t account for direction, this will only work in one direction - if you’re trying to hover your cursor under a roof, for example, it will go through the roof. Remember to account for the side of the block you’re hovering over.

Alright, I see your problem. I made something similar and also had trouble with this. An easy workaround was to just add half of the Part.Size to the target position, and it worked. I would do some raycasting to find the normal if I had to do it again and multiply the size by that instead.

I’m aware of this, I was just proposing a solution that will work in most cases. Unfortunately checking a single side is going to encounter the same issues checking the floor does, i.e; what if the part contacts two other parts, what if the part contacts the corner of another? The more verbose solution will require you to check each of the part’s surface normals to determine if or not it can move there.

To make it not to collide with floor you can add to it’s position it’s Size.Y.
Something like this

opticalpart.Position = Mouse.Hit.Position + Vector3.new(0,opticalpart.Size.Y,0)

Btw that would be strange if you mark this a solution because it is the same that said that guy and others below this topic.

Don’t see any problems with colliding because you are just setting it’s position to the point where is your mouse but your mouse is on the floor that’s why it’s position is on the floor and doesn’t collide with others.

Also you can check all collided parts with using BasePart:GetTouchingParts() and the add to it’s position theirs Size.Z or Size.X depending on difference between their x and z coordinates.