So I'm working on a small placement system, their isn't much to the code. But I am having a hard time figuring out how to detect collision with other parts they they place down. As well as how to make it so they can't place within like 1-2 studs of another part.
Here is my code so far:
local model = workspace.Brick; game:GetService("RunService").RenderStepped:connect(function() if mouse.Target then if mouse.Target.Name == "Baseplate" then model.CFrame = CFrame.new(mouse.Hit.p.X, mouse.Hit.p.Y, mouse.Hit.p.Z); else print('not good'); end end end)
Any help would be appreciated, thanks.
Well, you could get the size X of a part, and the size Z and then make kind of, a little box around the part with adding those to the position of the part. Like,
function detect(part) local partX = part.Size.X; local partZ = part.Size.Z; local pos = part.Position; local extendX = part.Position.X+part.Size.X; local extendOtherX = part.Position.X-part.Size.X; local extendZ = part.Position.Z+part.Size.Z; local extendOtherZ = part.Position.Z+part.Size.Z; --// Now you can use this, to create a box just on the border of your part's perimeter. Then you can check if there is a part within that border. Your welcome!