So I am making a Bloxburg esc game and I need to make a building system, obviously this comes with some challenges and one thats hit me hard is making a grid without the parts to go through, now I could use parts and likely not hurt performance by a lot but I expect to include rotation, and thats where this becomes tricky, now by rotation I mean the part being able to go to 3 different points, in front, left, and right. This is where the points system is handy but not entirely beneficial because I cant detect left and right easily. No placement system, at the moment, does all of what i want, including the points to brick conversion (2 points make 1 brick the size between the 2, the rotation via points, and the grid system. Now most do have the grid system thats still something I want to code myself or have a decent grid function without trying hard to go through someone elses code.
tldr how 2 do grids without making a ton of parts to grid to?
I would like this function to be kind of small but any size works as long as it isnt a giant script that shouldnt work like it does lol
I’m not sure I understand exactly what you are asking, but I think the solution you are wanting would be to round the Vector3 values to your grid.
local ROUND_TO = 5 -- studs
local function Round(Number)
return math.floor((Number / ROUND_TO) + 0.5) * ROUND_TO
local TargetPosition = Mouse.Hit.p
local RoundedTargetPosition = Vector3.new(Round(TargetPosition.X), Round(TargetPosition.Y), Round(TargetPosition.Z))
RoundedTargetPosition would be the position of the object you are placing on the grid.
EmeraldSlash’s solution is exactly what you are looking for, but I want to add something that could be useful for you. After putting a “thing” to a grid you will see that you don’t want to put things inside other things. At this point, I would suggest two things.
If your grid is big enough(Like 5 studs) and things can be rotated only 90 degrees, you can save those grids as busy with basic math. Putting a folder full of boolvalues that is named with grid’s X and Y coordinates could take care of you, and when something is placed, that thing makes those grids’ bools true.
If your grid will be very small(Like 0.2) and can be rotated freely, then I will suggest you Region3(To find out if there are parts in that region). But in this case you will need rotated Region3’s. You can use this article by EgoMoose for a rotated region3, but of course learn basic Region3 if you do not know it.
Good luck on your project!
Note: If anyone has better solution for second option, I would love to see!