r/Unity3D 21h ago

Show-Off Sphere cannot be build from hexes, but game dev is magic

Enable HLS to view with audio, or disable this notification

For our roguelite Tile Crawl, we wanted our meta progression to stand out, so we designed it as a planet to explore. But our run map was already designed using hexes, so for consistency's sake, we wanted a globe out of hexes as well. We did not want to have pentagons but rather somehow achieve full coverage by equal hexes (even though it is geometrically impossible).

So how it works:

This is actually a plane with objects placed on it. Then, using camera position, vertices are recalculated in a shader (all objects must share the same bending subgraph or shader code with the same values to look consistent). This technique is used in Animal Crossing, as far as I am aware, but just not tuned as heavily.

Okay, so this gives us a bent plane that looks like a sphere. Next challenge is actually allowing it to rotate properly; rotation is achieved by just moving the plane in the X and Y axes while the camera stays static. To achieve looping of the planes I am spawning 8 more planes with copies of the objects and then teleporting them as I am crossing the edges (this part for sure can be done way, way better with some vertex magic or just fewer clones).

Next challenge is that shadows are broken as vertices are recalculated but normals are not; to calculate a new normal, we need to get two neighbours of the vertex, then bend them with the same logic and use the results to calculate the new normal. This allows us even to have proper shadowing from clouds above.

Last thing to do is clicking the nodes on the map. As objects are actually in very different spots from visuals, just raycasting from the mouse won't work. So I'm using one big sphere collider to detect the mouse position on the sphere, then recalculate it backwards to where it would be on the plane and find the closest node in radius.

There are still some things left to do (VFX support is quite bad, and there are some artifacts with water waves on the edges of planes). But in my opinion, already looks quite good and stands out.

Thank you for reading! If you like what you saw, consider wishlisting Tile Crawl on Steam!

1.6k Upvotes

79 comments sorted by

221

u/SeregioFromTheSwamp 21h ago

I really like your planet design! Hex-maps are my favorite.

90

u/Silver4ura Intermediate; Available 20h ago

As the ol' saying goes: Hexagons are the bestagons!

20

u/softgripper 20h ago

Hexactly!

5

u/Nerood 20h ago

Hextastic!

2

u/SeregioFromTheSwamp 19h ago

Hexellent!

2

u/l3rva 17h ago

Hexlarious!

4

u/madhumster 19h ago

Thank you! We love them as well

2

u/pikuray 6h ago

Depends for what. RTS games? Terrible. Turn based? Sure.

40

u/Potato_Batteries 20h ago

Feels good knowing that people are still pushing boundaries and aren't afraid to step outside their comfort zone to achieve something beautiful. Kudos to you my friend <3

33

u/VolcanicA333 Indie 18h ago

That shader is a work of art. If you look closely, I think it's possible to see some geometric distortions characteristic for a plane spherization, but if you hadn't told I'd never notice. Great job, and juice is also really nice!

1

u/bpikmin 7h ago

Yeah it looks kinda like a magnifying glass put on a flat map. Still super cool though

50

u/NIKDEGame 21h ago

You definitely accomplished the task - your meta looks unusual and appealing

6

u/madhumster 21h ago

Thank you!

12

u/AnxiousIntender 19h ago

Congratulations, you made a torus! Actually I don't mind this kinda map design, old games did it and I never noticed as a kid. Looks awesome!

12

u/Bizsel 19h ago

So this doesn't actually behave like a sphere, right? Since a looped plane should topologically represent a donut rather than a sphere.

-1

u/ThetaTT 15h ago

Yes, and sadly it may make the map confusing (depending on the game).

It's possible to achieve a similar look with a cylindrical map, though (and restrict the camera position toward the poles).

5

u/Kenithal 18h ago edited 12h ago

Hmm I have to watch it again but I think it was a dev vlog about some minecraft style hexagon world. Where you can make a sphere out of hexagons but you need to have like some # of polygons (12 in memory) on the sphere that are actually 5* sided.

This is also a really cool approach and maybe even cooler especially on a smaller sphere (big nodes)

6

u/madhumster 18h ago

I seen it as well, what that developer achieved is very impressive!

2

u/rheno12 13h ago

Do you mean this one by Sebastian Lague? He mentions he eventually settled on an octahedron

1

u/Kenithal 13h ago edited 9h ago

It was this . Really interesting video, but I’ll have to give that one a watch too

2

u/4PianoOrchestra 9h ago

FYI you probably will want to remove the stuff after the ? on that link, when I click it it tells me your Google account (and name) saying “____ sent you this video”

1

u/Kenithal 9h ago

Thanks

1

u/uncreative_cc 12h ago

I was just about to reference that video.

That dude is brilliant, and the amount of time he put into the tooling and visual representations is underappreciated.

9

u/DaveAstator2020 20h ago

So how does it behave after numerous rotations? You can fake it only so long untill you have to get a pentagon somewhere, no?

26

u/madhumster 20h ago

We have a plane that can interlock with itself like a LEGO piece. Once the game is running, I am spawning 8 neighbours, making basically a 3x3 grid.
Let's say we are rotating from left to right. I am moving the whole grid to the left, and once the camera is over the right neighbour, it becomes the center and the left neighbour of the previous center becomes the right neighbour. Something like you would do in an endless runner.
As the map is in reality flat, there is no need to have pentagons.

As I mentioned in the post, I think this part can be done much better, as having 8 copies of the map is not optimal.

5

u/IsegrimGames 17h ago

That endless-runner comparison made the setup click for me. The cloud shadows sell the curvature so well that I never would’ve guessed there was a looping flat map underneath it.

2

u/DaveAstator2020 19h ago

huh neat, can it do roll rotation as well then? it should i guess. damn thats pretty clever

3

u/sam_suite Indie 13h ago

topologists hate this one weird trick to turn a torus into a sphere

1

u/gleedblanco 13h ago

it seems like with a continuous mapping something's gotta go. there's no continuous mapping from 3d sphere to 2d plane where you won't have to insert some stretch, or non-hexagonal shape to fill some gaps. since hexagons dont tile on 3d surfaces, and unwrapping to a plane is just turning your 3d surface into a 2d parametrization.

2

u/BuzzardDogma 11h ago

It's just an illusion of a sphere, there's no actual 3d geometry that the plane is mapping too. Think about it like using an extreme fisheye magnifying glass. When you "rotate" the sphere you are just moving the magnifying glass over the surface.

18

u/BattleFlyNate 20h ago

Says so in the post. It's a fake perspective of a plane, not an actual sphere.

4

u/DEADB33F 18h ago

The map is a flat plane that loops left/right and up/down.

(Essentially it's a toroid)

3

u/Oil_Aggressive 19h ago

Praise Be the Icosahedron

3

u/Repulsive_Gate8657 17h ago

So is it like a spherical lense what you move over flat looped 2d map?

2

u/tatsujb 20h ago

wow! what a solution! well done!

2

u/LKHGames 19h ago

Yo this is very cooooool

2

u/Hotrian Expert Moderator 19h ago

Looks amazing, and thanks for the detailed explanation :)

2

u/Due_Abbreviations205 19h ago

Looks really cool 🫡

2

u/SanoKei 19h ago

of that's fucking neat :o

2

u/LimitlessRetardation 18h ago

This is so beautiful.

2

u/XZPUMAZX 17h ago

Thanks for the write up. This looks really good.

2

u/Tychonoir 9h ago

Very cool!

A while back I was looking for how to tile a seamless hex grid into a square texture (older mobile requirements wanted square textures for efficiency.)

The problem is that the minimum tileable area isn't a square, and the number of these needed to exactly converge into a square ratio is prohibitively large.

I ended up building a tool to determine how many tiles are needed vs. what amount of distortion is acceptable to make it fit.

For example, an arrangement of 4x7 tiles will fit into a square area with a slight distortion of 1.053% This is basically imperceptible and acceptable for my use case. But the tool also shows other solutions depending on how much distortion you want to allow. If that's still too many tiles for a given texture, 3x5 works with a distortion of 3.776%

Anyway, it works with any ratio, so it's not limited to hexes.

4

u/weewoomeemoohee 18h ago

meanwhile, i still cant understand how a state machine works after watching 10+ videos.

man, im not built for this.

3

u/madhumster 18h ago

You will get there! I am doing this for almost 10 years already, though shaders are not my specialty.

1

u/LemonUnit1 20h ago

Wow, looks beautiful!

1

u/madhumster 20h ago

Thank you!

1

u/rimnas12 18h ago

I rarely play such games, but this is so satisfying and beautifully made it makes me want to unlock everything 😂 well done!

1

u/_OVERHATE_ 17h ago

Modern Tetrisphere

1

u/XxDrFlashbangxX 16h ago

Wow this looks awesome

1

u/blu3bird 16h ago

Naise.

1

u/tutmoBuffet 16h ago

This is so neat! Thanks for sharing your method behind the illusion, very clever.

1

u/I_HAVE_THAT_FETISH 14h ago

You can definitely see some warping when the "sphere" moves quickly, but I think it actually adds to the atmosphere.

Most players likely won't notice, and I can't imagine those who do will complain as it looks very cool.

1

u/Apprehensive_Lake698 13h ago

I think with prior knowledge there are ways to nitpick, but if the user has no idea about hexagon tiling and doesn’t have any reason to suspect it, this is a 100% convincing solution. Very creative!

1

u/Enchrypted 13h ago

I for one never thought about the fact that hexagons couldn't make a sphere but it looks neat!

1

u/Malkalypse 12h ago

Fantastic effect! There are probably a couple other ways to achieve it but I don’t know that they would get better results, and what you have 100% works, so keep it!

1

u/pyabo 12h ago

Mathematicians hate this one trick!

Looks great! The whole aesthetic with the art and palette. Just very smooth and great presentation there. Now quit violating the laws of spacetime.

1

u/mllhild 12h ago

Seem like a lot of work to hide the fact that its not a sphere. Given that the pentagons dont have to be always in the same position, just having them as special tiles would have been fine as well. A player would have never questioned it.

1

u/annias 12h ago

Did something similar (not in unity) on a multi planet 4x type game that is released but also very much still in development @ https://www.spawn.co/@annias/orbitalis/play

1

u/annias 12h ago

I'm still very much working out the UI / UX but y'all are free to check it out as desired for inspiration or to play. I want to really smooth things out so it's easy to navigate and understand, but the core concept of the hex space planet thing like the OP is there <3

1

u/BucketCatGames ??? 11h ago

"all of these hexes make a sphere, all of these hexes make a sphere" - mr popo, probably

1

u/glitchspire-studio 11h ago

Looks pretty cool! Hopefully I can make some awesome effects like this someday.

1

u/Fr1k 11h ago

And you’re a wizard! 🧙‍♂️

1

u/kaiiboraka 11h ago

The visual design reminds me much of the board game Runebound. Very snazzy!

1

u/potatoman445 10h ago

is it a flat plane projected to a sphere?

1

u/ImprovementBig3354 9h ago

Dude, that is fucking beautiful. Amazing stuff :)

1

u/Comfortable_Rip5222 Hobbyist 9h ago

I made something similar, maybe can help, I made using curved world

https://youtu.be/jHQDsnhS-Y4?is=eWaaRJP_-ICySKh6

1

u/HoveringGoat 8h ago

where are you hiding the pentagons?

edit: nvm this is very clever shader magic. So presumably there should be stretching/artifacts but you can keep them off screen? Hows it look if the map fully tiles a planet?

1

u/Suspicious-Map1444 7h ago

A planet with clouds! Innovative! It toke my attention. Beautiful.

1

u/Gold-Target-5462 7h ago

This reminds me a bit of how tetrisphere for N64 works. You can't map squares onto a sphere, so it's really a torus with the camera tweaked to look like a sphere. The problem is of course that if you rotate about the sphere and track the position of squares everything is wrong

1

u/Quick_Trick3405 6h ago

Uh, .... Cool.

1

u/GreggoryAddison 5h ago

My god this is beautiful

1

u/MusicOfTheApes 5h ago

Wow excellent design and creative !
I noticed you don't have any bgm in this video, if by any chance you're looking for a composer I'd be very interested !
Congrats anyway, can't wait to see how it's gonna turn out

1

u/qK0FT3 3h ago

I feel like this is some kind of grid mapping on a flat plane but with lense effect + repeat? I have done something very similar with fake earth on a website 10 years ago. Not sure how you do it tho.

Edit: i read the post fully after this and it seems like it is pretty similar lol.

1

u/Opening-West-4369 21h ago

nice! check out Uber's h3 library might be helpful for this https://www.uber.com/us/en/blog/h3/

1

u/Jacmac_ 18h ago

A sphere can be made from hexes, in fact most GIS companies use Isosahedrons. There are 12 pentagons in the sphere, but if you subdivide the triangles with enough iterations the pentagons become so small that they are not much more than tiny artifacts.

-3

u/swagamaleous 20h ago

Spheres actually can be built from hexes. You just need to add 12 pentagons. You can make a huge sphere with 99% hexagons, and just evenly space out the 12 pentagons. That's how a soccerball does it as well.

4

u/madhumster 20h ago

Yeah we could, but as you said, you always need 12 pentagons no matter the size of the sphere, even if the sphere is small(and we are a very small team; no way we're gonna have 1000 hexes meta progression).

Also, with those 12 pentagons, hexes around them will actually not be regular hexagons.

For these reasons, visual appeal and technical challenge of achieving this we went with this approach.

3

u/Apprehensive_Lake698 13h ago

“It can be built from hexes, as long as you add non-hexes” I am gonna take a while guess and say that’s true for most shapes.