i have a project with an infinite grid and cells on the grid can be alive or dead. if i have a living cell. how can i tell if cells that border it are alive or dead?
(im probobly really dumb and its super simple but i am really dumb)
i have a project with an infinite grid and cells on the grid can be alive or dead. if i have a living cell. how can i tell if cells that border it are alive or dead?
(im probobly really dumb and its super simple but i am really dumb)
However cells are addressed, modify that address to point to their neighbor cells and iterate those.
When your grid is “infinite” how do you index the cells since numbers in computers can only represent a finite value?
As for your question: A grid is defined by coordinates. So you may need a method to query the cell at a given coodinate. So when you are at 5,2 and want the cell up from this you search for 5,3.
Edit: There was a quote from Einstein about infinity but I don’t remember it ;).
Might need more info on your infinite grid, since that is not actually possible.
when i say infinite grid i litteraly mean im using the coordinate/tile system unity gives you and need to tell if a tile is being ocupied
ok ill defenitly try that
i guess my way of doing it(which is really clunky cause i suck at coding) would to just make every cell have colliders on each side and if they are being touched trigger somthing in the script
Don’t do that. If you use colliders/physics for such stuff your grid will be even smaller than now.
Here I have explained how I would do it in a similar usecase. When only a small part of the grid is visible to the player (and action happens only there so there is no simulation of the outer parts) I would even avoid using game objects for the whole grid but just have a data representation (non MB class) and when player moves the data around him is loaded and the tile representation is created from that.
So in general you need a manager class which has access (or stores) all your cell data. This one is responsible for getting you information about a certain cell to check if it is “occupied” (whatever that means).
The only way to get better is practicing ;). And maybe a bit of reading (forum, books, blogs).