So the black square is the block that has already been placed, the green squares is the place where I can place blocks, but the red is where I cannot place blocks.
I don’t want this to happen.
Here is the script(It is all done on client side):
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
local ToolEquiped = false
function round(number, to)
return math.floor((number / to) + 0.5) * to
end
local TestPart = Instance.new("Part")
TestPart.Parent = workspace
TestPart.Size = Vector3.new(5,5,5)
TestPart.BrickColor = BrickColor.new("Institutional white")
TestPart.Transparency = 0.5
TestPart.CanCollide = false
TestPart.Anchored = true
Mouse.TargetFilter = TestPart
Tool.Equipped:Connect(function()
ToolEquiped = true
while ToolEquiped == true do
TestPart.Position = Vector3.new(round(Mouse.hit.p.X, 5),round(Mouse.hit.p.Y, 5) , round(Mouse.hit.p.Z, 5))
wait()
end
end)
Tool.Unequipped:Connect(function()
ToolEquiped = false
end)
Tool.Activated:Connect(function()
local Block = TestPart:Clone()
Block.Parent = workspace
Block.CanCollide = true
Block.Transparency = 0
end)
Here is a link to the game so that you can see what I mean(There are still other things that I need to fix):
I’m afraid I’m not sure (as a quick answer), I’m more into back-end processing than 3D geometry, just I remembered that post and thought it would be of use, sorry.
The geometry is not actually needed if you use the right trick, you just need to be smart about how you’re biasing the block position.
When your mouse click happens, the hit lands exactly on the side of the block, but that means that it’s exactly on the edge between two blocks. Your code has to have some way to disambiguate which of the two potential “sides” of the click to put the block on.
The easiest way to do this is to subtract the camera direction (Camera.CFrame.LookVector) multiplied by a very small bias (like, 0.01 or something), from the hit position. That way you will always choose the empty space (if the space closer to your camera was the full space… the hit would have happened earlier, so the space closer to your camera must be the empty one)