I am making a grid placing system for my circuitry game, but there is a flaw in my code for the blocks are snapping into each other on certain sides. Has anyone else experienced this? Please assist me
My code:
function raycast(parts)
local params=RaycastParams.new()
params.FilterDescendantsInstances=parts
params.FilterType=Enum.RaycastFilterType.Include
local m=workspace.CurrentCamera:ViewportPointToRay(mouse.X,mouse.Y+game.GuiService.TopbarInset.Height)
return workspace:Raycast(m.Origin,m.Direction*1000,params)
end
local pos=raycast({workspace.Blocks:GetDescendants(),workspace.roblox:GetDescendants()})
if not pos then return end
pos=pos.Position:Ceil()-Vector3.one*.5
It looks like you are only subtracting the Vector3, but wouldn’t that just place it to the negative side of the surface the mouse is on.
Also, are you using math.round or math.ceil for the placement? Round would work better because it rounds up or down based on the mouse position, where ceil would always go to the highest point (example 32.1 using ceil is 33, but using round would be 32)
There are a lot of other solved posts about making grid snapping or building game placement. I’m pretty sure most of them are using the mouse position instead of a raycast, then just placing the blocks on a rounded grid type setup.