Object not correctly offsetting after rotating

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 need to know how far the bottom of the part is from where it is grabbed for each rotation. You can do by making a table and filling it out manually. Or I have a module which does this and you set it up by placing attachments on each side: GridPlacer: Highly-featured module for part placement, rotation, and snapping to grid - Resources / Community Resources - Developer Forum | Roblox

hmm ig i will give this module a shot

hmm didn’t work…

btw what do you mean by the table?

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.

i make like table with vector3.axis?

if not then you can show an example

Yes you can use a Vector3 as a table index and a number as the value, to tell how long the object is in that direction.

can you show me an example please?

For a 3x2x1 placement box you might have:

placementHeights = {}
placementHeights[Vector3.xAxis] = 1.5
placementHeights[-Vector3.xAxis] = 1.5
placementHeights[Vector3.yAxis] = 1
placementHeights[-Vector3.yAxis] = 1
placementHeights[Vector3.zAxis] = 0.5
placementHeights[-Vector3.zAxis] = 0.5

mmm okay but what do i have to do now?