How do i set the grid placement within the build zone

Hello developers! So im currently making a 1x1 grid placement system and i would like to know how to snap the grid inside the build zone part. Here is an image of the small brick wall im trying to place inside the build zone. as you can see it doesnt cover the corners. I would like it to snap to the corners first.

image

image

1 Like

You want the grid to be based on the zone part instead of world space?
I’m assuming you’re doing something like this to snap your placed part/object to a grid.
placedPart.Position.X = math.round(mouse.Hit.Position.X)

Instead of that, you need to get your mouse’s location in relation to your zone part and then round it.

local relativeX = mouse.Hit.Position.X - buildZonePart.Position.X
local rounded = math.round(relativeX)
local finalX = buildZonePart.Position.X + rounded

(You of course need to do this for each axis)

You can translate the placement position into the space of the build zone part, then applying the snap function (which I gave you in your previous thread), then convert it back into world space.



--Assume playerSelectedPosition is the position the player is aiming at with the mouse
--Assume grid is the grid size in blocks

local buildZoneSpacePos = buildZonePart.CFrame:PointToObjectSpace(playerSelectedPosition)
local snappedPos = Vector3.new(math.round(buildZoneSpacePos.X / grid), math.round(buildZoneSpacePos.Y / grid), math.round(buildZoneSpacePos.Z / grid)) * grid
local finalSnappedWorldPos = buildZonePart.CFrame:PointToWorldSpace(snappedPos)
1 Like