I’ve been trying for a few days now to create a builder tool. It mostly functions as intended.
When I create a new part using my tool, it places correctly on the grid however if I try to place a part off of another part, it clips into its side.
How can I avoid that and force the part to “offset” itself in such a way that it places next to it instead of partly inside of it?
Here are some examples of how the tool works and how I want it to work:
The intended result is in the background
Here’s the part of the code that handles part creation:
if not newpart then
newPart()
elseif newpart then
if canplace then
local sentpart = {}
sentpart.Size = newpart.Size
sentpart.Position = newpart.Position
sentpart.Anchored = newpart.Anchored
sentpart.CanCollide = newpart.CanCollide
sentpart.Orientation = newpart.Orientation
game.ReplicatedStorage.BuilderTool:FireServer("New",sentpart)
newpart:Destroy()
newpart = nil
end
end
and here’s what handles the canplace
condition:
RS.RenderStepped:Connect(function()
if func == 1 then
if newpart then
local mousepos = mouse.Hit.p
newpart.Position = Vector3.new(math.floor(mousepos.X),math.floor(mousepos.Y)+newpart.Size.Y/2,math.floor(mousepos.Z))
local parts = newpart:GetTouchingParts()
if #parts > 0 then
canplace = false
newpart.BrickColor = BrickColor.new("Bright red")
else
canplace = true
newpart.BrickColor = BrickColor.new("Bright green")
end
end
end
end)
What I thought I could do was create the offset using magnitude between the two parts but unfortunately upon further research it would only work with parts that are equal in size and parallel.
Edit: Is it possible that I’d have to create a virtual grid? Although I don’t think that would function well as you could move parts off-grid using the move tool and unanchor tool and I’d like to be able to snap on parts to those parts too. Ideally I’d like it to function like the copy wand from build games.