I want my building system similar to build a boat for treasure’s building system but parts go in each other and dont snap when I turn on grid mode
video:
client raycasting lines:
local pc = require(tool.placement_calculator)
local raycast = workspace:Raycast(unit_ray.Origin, unit_ray.Direction * 1000, params)
if raycast and preview and equipped and building then
local normal_cf = CFrame.lookAt(raycast.Position, raycast.Position + raycast.Normal)
local relative_snapped = normal_cf:PointToObjectSpace(raycast.Position)
local x_vector = normal_cf:VectorToWorldSpace(Vector3.xAxis * -math.sign(relative_snapped.X))
local y_vector = normal_cf:VectorToWorldSpace(Vector3.yAxis * -math.sign(relative_snapped.Y))
local cf = CFrame.fromMatrix(raycast.Position, x_vector, y_vector, raycast.Normal)
local adjustment_direction = raycast.Normal.Unit
local normal_adjustment = adjustment_direction * (math.abs(preview.Size:Dot(adjustment_direction)) / 2)
local grid = true
if grid then
preview.Position = pc.snap_to_grid(cf.Position + normal_adjustment)
else
preview.Position = cf.Position + normal_adjustment
end
placement calulator:
local GRID_SIZE = 3
local module = {}
function module.snap_to_grid(pos, normal)
return Vector3.new(
pos.X // GRID_SIZE,
pos.Y // GRID_SIZE,
pos.Z // GRID_SIZE
) * GRID_SIZE
end
return module