-
What do you want to achieve?
I want to make my block building system snap to grid a vertically tall block (which is 4x8x4 studs). -
What is the issue?
The block appears to be floating half a block (2 studs).
local pos = hit.Position + hit.Normal * offset
pos = Vector3.new(
math.floor((pos.X + offset.X) / 4) * 4,
math.floor((pos.Y + offset.Y) / 4) * 4,
math.floor((pos.Z + offset.Z) / 4) * 4
)
local pivot = CFrame.new(pos) * rot
ghostBlock:PivotTo(pivot)
This is the code which pushes the block in the normal and snaps it onto the grid.
hit
is the RaycastResult
from workspace:Raycast()
method.
offset
is the block’s size divided by 2.
-
What solutions have you tried so far?
I have tried tried changing the offsets but none of them work.
I also tried searching for answers but there aren’t any.
I searched through Stamper Tool by Maximum_ADHD but I can’t wrap my head around it.
I’m trying to make a door in my block game but I can’t make different sized blocks work properly. When the blocks are 4x4x4, their centers are at 2, 2, 2. But when it is 4x8x4, it is at 2, 4, 2 which makes it float 2 studs. When I change the offset to subtract 2, it also changes the 4x4x4 positioning, making it go underground 2 studs. Is there a method to position any multiple of 4 sized block without using conditions? Or do I need to use conditions?