Trying mouse.hit only makes a worse problem
Here is part of the script that makes this system
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not pickedUpPart then
if (mouse.Hit.Position - character.Head.CFrame.Position).magnitude < 10 then
if mouse.Target then
if mouse.Target.Anchored == false then
-- Pickup part
pickedUpPart = true
part = mouse.Target
part.Anchored = true
mouse.TargetFilter = part
local connection
connection = game:GetService("RunService").RenderStepped:Connect(function()
if not pickedUpPart then mouse.TargetFilter = nil connection:Disconnect() return end
local loc = CFrame.new(character.Head.Position, mouse.Hit.Position)
part.Position = (loc + (loc.LookVector*10)).Position
part.Orientation = Vector3.new(0,0,0)
end)
end
end
end
end
end)
I would like to know how to make so when the part hits a wall, it just sticks around instead of clipping.
are you using raycast to find out the position it should be in? just detect what surface of a part it is touching and offset it by the correct amount for that ill give u code in 1 sec if i can find some in my old project
ok, but how would the offset be calculated tho? Also it doesn’t look like a raycast, but a cframe location with the direction pointing to mouse.hit and the position would be modified by its lookvector.
sorry for the wait just made a quick code demo by putting together some code i found in old projects
local target,pos,norm = nil
local MaxPlaceDistance = 50
local mouse = game.Players.LocalPlayer:GetMouse()
local part = Instance.new("Part",workspace)
part.BrickColor = BrickColor.new("Lime green")
part.Anchored = true
part.Transparency = 0.5
part.CanCollide = false
function UpdatePosition()
local ignoreList = {game.Players.LocalPlayer.Character}
if part ~= nil then
table.insert(ignoreList,part)
end
local mouseRay = mouse.UnitRay
local newRay = Ray.new(mouseRay.Origin, mouseRay.Direction.Unit * MaxPlaceDistance)
target, pos, norm = workspace:FindPartOnRayWithIgnoreList(newRay, ignoreList)
end
mouse.Move:Connect(function()
UpdatePosition()
local endPos = pos + (norm * (part.Size * 0.5))
part.Position = endPos
end)
put this in a local script in startergui or some other service that runs local scripts and you will see that it works well and you can take the code out and implement it into ur system