For some reason ive been trying to make this placement system. I was raycasting to see if it would collide with objects and stuff but for some reason the object never moves to the mouses position. Anyone know why?
if placingobject == true then
mouse.TargetFilter = previewobject
if previewobject:FindFirstChild("MainPart") then
local ignoreList = {game.Players.LocalPlayer.Character}
if previewobject ~= nil then
table.insert(ignoreList,previewobject)
end
local mouseRay = mouse.UnitRay
local newRay = Ray.new(mouseRay.Origin, mouseRay.Direction.Unit * 35)
target, pos, norm = workspace:FindPartOnRayWithIgnoreList(newRay, ignoreList)
end
else
previewobject:Destroy()
end
if placingobject == false then
script.Parent.Inventorybtn.Visible = true
script.Parent.Rotation.Visible = false
end
end)
no But I found a problem I forgot to set the primarypartsCFrame. Can you help me turn this code into something that precents the previewobjects from clipping into walls?
if placingobject == true then
mouse.TargetFilter = previewobject
if previewobject:FindFirstChild("MainPart") then
local objectcframe = CFrame.new(math.round(mouse.Hit.Position.X/grid)*grid,math.round(mouse.Hit.Position.Y+previewobject.PrimaryPart.Size.Y/2), math.round(mouse.Hit.Position.Z/grid)*grid)
local objectangles = CFrame.Angles(0, math.rad(rotationamount), 0)
previewobject:SetPrimaryPartCFrame(objectcframe*objectangles)
end
else
previewobject:Destroy()
end
if placingobject == false then
script.Parent.Inventorybtn.Visible = true
script.Parent.Rotation.Visible = false
end
end)```