I’m working on a voxel mining game, no need for more information, it spawns new blocks by offsetting the blocks by 6 studs on all sides. Some of these blocks however, use cylindrical constraints to make cool looking ores, this means that they are likely unanchored and therefore may occasionally have their position slightly off, causing multiple blocks (seemingly) on the same position or halfway to the next position.
I tried preventing this by rounding the position of the ore and using that as the value to make new blocks with like this
local pos = Vector3.new(math.round(t.Position.X), math.round(t.Position.Y), math.round(t.Position.Z))
however this still occasionally breaks and it still goes off-grid sometimes. Is there any other method to round numbers that’s more reliable?
I would make a hitbox for each of the ores, and all of the hitboxes in all of the ores are the exact same size. They are invisible and have cancollide set to true, and every other decoration in the ore’s cancollide set to false. When you are setting the position of the ores make the base position of the ore the hitbox. This ensures that each block has the exact same size and therefore there will be no issues with block generation
It might be worth rethinking stuff from the top, you probably want some sort of chunk object, that contains the grid position of all the local voxels… so a 3d array containing pointer to the voxel objects, this would allow you to lookup, save and place blocks based on their index in the chunk array. meaning you wont have to do any offsetting calculations…