I have been stuck on this all day. The issue is that whenever I place blocks of different height, but same size of 4 on the X and Z, the part wants to go either into the ground more than it should, or into the air more than it should. I've tried using the knowledge of what I know, but haven't been able to figure it out.
I have some pictures showing the what the issue is and what the issue should look like when it is fixed; they are listed below...
This is what the issue is at the moment, as you can see they are not incrementing by 4 because they are in the ground a certain amount, which is something i cannot determine.
https://imgur.com/a/GnRaRu4
This is what the issue should look like when it's resolved; when it is actually working and stackable with all blocks that have an increment of 4.
https://imgur.com/a/yVF607V
Here is the code that I have been working to try and get it to snap to the grid properly. Most of the variable names that are not listed should be self explanatory.
HighlightModel is the model that is being dragged before being placed, basically a clone of the blocks seen in the image. GridPlacementPart is what the baseplate is made up of, (1024) blocks that are 4x4x4` PlacedBuildingObject is the same thing as the HighlightModel. GridSize is a value of 4
function Grid:returnGridSnapCFrame(Mouse, HighlightModel, GridSize, Player) local PlateGridParts = GetLocalPlayerPlate(Player).PlateGridParts local TargetSurface = Mouse.TargetSurface local Target = Mouse.Target local HighlightModelSize = GetObjectSize(HighlightModel) if(Target) then if(Target.Name == "GridPlacementPart" or Target.Name == "PlacedBuildingObject") then if(TargetSurface == Enum.NormalId.Top) then if(HighlightModelSize.Y > 4 and HighlightModelSize.Y < 12) then return Target.Position + Vector3.new(0,GridSize%HighlightModelSize.Y + (Target.Size.Y / 2), 0) elseif(HighlightModelSize.Y >= 12) then return Target.Position + Vector3.new(0,(GridSize%HighlightModelSize.Y), 0) else return Target.Position + Vector3.new(0,HighlightModelSize.Y, 0) end end end end end
Please, help is appreciated and I would really like it if this issue could finally be resolved.