Hello, I wrote a small object moving system for my game, when I use it though parts go into the ground and go into other parts, how could I and what are some ways I could fix this?
Btw these pictures of me using the system and having the thing happen:
Here is my script for further context:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mtarget
local down
function clickObj()
if mouse.Target ~= nil and mouse.Target:IsDescendantOf(game.Workspace.Objects) then
mtarget = mouse.Target
print(mtarget)
mouse.TargetFilter = mtarget
print(mouse.TargetFilter)
down = true
end
end
mouse.Button1Down:Connect(clickObj)
function mouseMove()
if down and mtarget then
local posX,posY,posZ = mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z
mtarget.Position = Vector3.new(posX,posY,posZ)
end
end
mouse.Move:Connect(mouseMove)
function mouseDown()
down = false
mtarget = nil
mouse.TargetFilter = nil
end
mouse.Button1Up:Connect(mouseDown)
To avoid the part going through the ground you need to increase the Y Position of it with half the Y Size. Should be the same thing with all other directions too.