Enforcing adjacency (contiguous indices in hexagonal grids are *fun* to work with)

Our game's first bee (or at least, the first bee generated by the population handling system I'm writing) \o/

@mattmcnutt I saw this notification thinking "This had better be Dr Bees"

@Cheeseness I've been told that hex grid cells are best addressed with 3D coordinates, because adjacencies are easier. Is that what you're doing here?

@impiaaa Nope, I'm doing a boring old 2D grid, and calculating adjacency with this mess (this function builds a cluster of 7 tiles). A little dodgey, but it's working \o/

@impiaaa If I were refactoring/making bigger, I think I'd store references in each node to adjacent nodes rather than relying on positions in data structures, and just use lists for stuff that needs to check every cell

@Cheeseness That sounds… expensive. I guess each cell is already a whole game object, but that's still 6 extra pointers per cell. I'd prefer an array.

(I was actually working on a grid-based strategy game, and while it was squares, it was diagonal and arranged that way, so I similarly had complicated coordinates. Not so bad with helper functions, but still one thing I'd go back and fix.)

@impiaaa Yeah, with the overhead of Godot's Node class, a handful of pointers doesn't feel like much in the grand scheme of things.

Blundering through this kind of stuff is a positive learning exercise, I figure. If you come out the other side with a better solution for next time, that's a win :)

@Cheeseness @impiaaa Funny, I wondered exactly how to do this when I saw your beehive stuff.

This looks pretty darn confusing and it's asymmetrical as well. I can see how triplets, and hence a number per axis. per would make this a bit easier.

Obviously that would work like a charm for hexes adjacent to the origin, since all of them are on axis. Further out there'd be hexes off-axis as well and it would get a bit weird either way.

@murks @impiaaa Every second cluster of three ends up inverted, so triplets would be pretty awkward, yeah?

A "crushed" 2D grid with fat columns feels pretty simple conceptually - easy enough to implement, but messy in the resulting code.

@Cheeseness @impiaaa Well that idea fell apart pretty quickly. Three hexes out I could choose between losing uniqueness and awkward numbering.

@Cheeseness @impiaaa I'm sure it has been done to death, so I did a quick search. This seems like a page that describes hex grids well, with a number of variants. redblobgames.com/grids/hexagon

@murks @impiaaa Yeah, definitely a solved problem by now. For stuff like this, it's fun to explore first, then research (you can never truly understand the wheel until you take the time to invent it, I say). The "offset coordinates" solution there is what I ended up with.


I'm getting flashbacks to my final year project at University - a short 3D animated movie to the music of The Flight of the Bumblebee.

Loved my little bee. Even rigged up his antennae to they bent back during flight.

Little guy is lost the digital heaven on a Zip disk somewhere... 😢

@kevinbeynon Aww, I hope you manage to unearth it someday. That stuff is treasure <3

@Cheeseness Thank you!

I was so proud of it. Especially since each scene took all night to render on 3D Studio 4... not Max.

Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!