hello robloxian developpers! While i was developping my game, i ran into a small roadblock about offseting part (snapping).
when rotated, part sometimes doesn’t offest correctly…
i couldn’t find any solutions nor anyone wanna help me out on discord…
this post is my last resort
i would love if anyone could help! cheers!
Part of chunk of main build module:
local PrimPart = self.PreviewObject.PrimaryPart::BasePart
local Snap = gridModule.gridSnap(cast.Position,snapVal)
local cf = CFrame.new(Snap)
local vectSnap = cf:PointToWorldSpace(cast.Normal * (PrimPart.Size/2))
self.PreviewObject:MoveTo(vectSnap)
small util module:
local function roundNumberToBase(number: number, base: number, floor: boolean?): number
return floor and math.floor(number / base) * base or math.round(number / base) * base
end
function grid.gridSnap(x,snapVal)
return Vector3.new(
roundNumberToBase(x.X,snapVal),
roundNumberToBase(x.Y,snapVal),
roundNumberToBase(x.Z,snapVal)
)
end
You’d make a table of how far it is from where the object is grabbed to the bottom surface it gets placed on, since it will be different for each side, for anything that isn’t a perfect cube.