Hello!
I was wondering how I would snap an object relative to the plot. For example, I will provide what I expect versus what actually happens.
Expectation:
What actually happens:
Script to place the object:
local function SnapTo(num, inc)
return math.round(num / inc) * inc
end
mouse.TargetFilter = model
for i,v in pairs(model:GetDescendants()) do
if v:IsA('BasePart') then
v.CanCollide = false
if v.Name ~= 'BoundingBox' then
v.Transparency = 0.5
else
v.Transparency = 1
end
end
end
local gridPart = workspace.Plot
local placementPosWorld = mouse.Hit.Position
local gridNodeSize = module.GridSize
local s,e = pcall(function()
model.Parent = gridPart
end)
if not s then return end
local yPos = gridPart.Size + (gridPart.CFrame.UpVector * (gridPart.Size.Y / 2))
model:SetPrimaryPartCFrame(CFrame.new(SnapTo(mouse.Hit.Position.X, module.GridSize), gridPart.Position.Y + (model.PrimaryPart.Size.Y / 2), SnapTo(mouse.Hit.Position.Z, module.GridSize)))
if rotation ~= 0 then
model:SetPrimaryPartCFrame(model.PrimaryPart.CFrame * CFrame.Angles(0, math.pi / 2 * rotation, 0))
end
return model