#best way to setup a three-dimensional grid?

1 messages · Page 1 of 1 (latest)

kindred dawn
#

im making a game and i want a three dimensional grid (probably around like 20x20x20 or so, likely less) that'll hold blocks/pre-defined items. (i promise this isnt minecraft slop 😭)
i've been thinking of methods on how to do it, but im dumb so like im asking what would be the best way to do this

context: objects will probably be internally referred to with a struct or smth (position relative to center/pivot), with their definitions probably just being ints (or int adjacent idk man theres like 20 different number types in c#).
performance target is preferably low-end pcs/chromebooks

south dune
#

really depends what you're going for here. 20x20x20 isn't crazy large that you'd need to worry about how you store this data.
i'd think of how you actually intend to use this before anything. Like does every space hold a block/item or will most of these be empty? What are these blocks supposed to represent in your actual game?

kindred dawn
#

most will be empty

#

idea is that you have a camera around the grid and you're able to drag on other blocks (connecting them) or selecting and dragging pre-existing blocks

#

with some "blocks" being able to be inside other ones

#

most objects arent actually blocks (most have unique functions) but im just referring to them as blocks for simplicity sake

south dune
#

You could probably just create a class with a vector3 and any information you want associated with each block. The vector3 represents where they are
Have a list of this new class to track where everything is

kindred dawn
#

yeah i was thinking of that

#

i was just asking cuz ive never rly done grids like that before, and maybe it was inefficient??

south dune
#

🤷‍♂️ at 8000 elements you aren't gonna notice performance issues. prioritize usability here

#

like if its easier to code it using a multidimensonal array of [20,20,20] then do that instead

#

or a 1d array of 8000 elements where u manually calculate the index based on the xyz

kindred dawn
#

fair

south dune
#

the performance issues is gonna come from the unity stuff you're doing. Like if you have 8000 game objects, thats gonna be a big problem

kindred dawn
#

yeah no 😭 im thinking of ways to prevent 8000 objects at max

#

if not more

south dune
#

if u have more of a description as to what this is for, maybe people will have ideas. Like if these are actual blocks that people stand on (minecraft) then you shouldnt be representing like this in the first place

#

if its just some playground where users can spawn blocks at will, then let them spawn it and (possibly) lag their pc.

kindred dawn
#

essentially you can build smth, and then let it "run" and the whole product gets affected by physics

#

i already know how to generally optimize that however (custom physics mesh)