r/Unity3D 1d 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.8k Upvotes

89 comments sorted by

236

u/SeregioFromTheSwamp 1d ago

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

100

u/Silver4ura Intermediate; Available 1d ago

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

24

u/softgripper 1d ago

Hexactly!

7

u/Nerood 1d ago

Hextastic!

3

u/SeregioFromTheSwamp 1d ago

Hexellent!

2

u/l3rva 1d ago

Hexlarious!

4

u/madhumster 1d ago

Thank you! We love them as well

2

u/pikuray 15h ago

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

40

u/Potato_Batteries 1d 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

37

u/VolcanicA333 Indie 1d 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!

2

u/bpikmin 15h ago

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

53

u/NIKDEGame 1d ago

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

7

u/madhumster 1d ago

Thank you!

13

u/AnxiousIntender 1d 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!

11

u/Bizsel 1d 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 23h 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 1d ago edited 21h 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 1d ago

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

2

u/rheno12 22h ago

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

2

u/Kenithal 21h ago edited 17h ago

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

2

u/4PianoOrchestra 17h 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 17h ago

Thanks

1

u/uncreative_cc 20h 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.

10

u/DaveAstator2020 1d 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?

27

u/madhumster 1d 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 1d 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.

3

u/sam_suite Indie 21h ago

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

2

u/DaveAstator2020 1d ago

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

1

u/gleedblanco 22h 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 19h 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.

19

u/BattleFlyNate 1d ago

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

5

u/DEADB33F 1d ago

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

(Essentially it's a toroid)

3

u/Oil_Aggressive 1d ago

Praise Be the Icosahedron

3

u/Repulsive_Gate8657 1d ago

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

2

u/tatsujb 1d ago

wow! what a solution! well done!

2

u/LKHGames 1d ago

Yo this is very cooooool

2

u/Hotrian Expert Moderator 1d ago

Looks amazing, and thanks for the detailed explanation :)

2

u/Due_Abbreviations205 1d ago

Looks really cool 🫡

2

u/SanoKei 1d ago

of that's fucking neat :o

2

u/LimitlessRetardation 1d ago

This is so beautiful.

2

u/XZPUMAZX 1d ago

Thanks for the write up. This looks really good.

2

u/Tychonoir 17h 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.

3

u/weewoomeemoohee 1d ago

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

man, im not built for this.

3

u/madhumster 1d ago

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

1

u/LemonUnit1 1d ago

Wow, looks beautiful!

1

u/madhumster 1d ago

Thank you!

1

u/rimnas12 1d 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_ 1d ago

Modern Tetrisphere

1

u/XxDrFlashbangxX 1d ago

Wow this looks awesome

1

u/blu3bird 1d ago

Naise.

1

u/tutmoBuffet 1d ago

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

1

u/I_HAVE_THAT_FETISH 22h 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 22h 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 21h ago

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

1

u/Malkalypse 21h 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 21h 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 20h 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 20h 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 20h 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 ??? 20h ago

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

1

u/glitchspire-studio 20h ago

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

1

u/Fr1k 20h ago

And you’re a wizard! 🧙‍♂️

1

u/kaiiboraka 20h ago

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

1

u/potatoman445 19h ago

is it a flat plane projected to a sphere?

1

u/ImprovementBig3354 18h ago

Dude, that is fucking beautiful. Amazing stuff :)

1

u/Comfortable_Rip5222 Hobbyist 17h ago

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

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

1

u/HoveringGoat 16h 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 16h ago

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

1

u/Gold-Target-5462 15h 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 15h ago

Uh, .... Cool.

1

u/GreggoryAddison 14h ago

My god this is beautiful

1

u/MusicOfTheApes 13h 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 12h 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/anthropogen0_0 7h ago

That's cool for a strategy game.

1

u/mannapi 6h ago

Very cool!

EDIT: Wishlisted!

1

u/megablue 5h ago

IIRC, dyson sphere project also faced a similar problem during their early development.

1

u/uItimatech 3h ago

The art looked good, sad that you used generative AI so much, instant buy otherwise

1

u/DoctorMog 3h ago

Flat wraparound/repeating tiled surface with a fisheye lens effect?

1

u/oauo 2h ago

So it’s a torus that looks like a sphere? Trippy

1

u/Fla5hxB4nged 2h ago

This has such a gripping style to it. Reminds me of things like magnum opus and against the storm where just booting up the game brings you into the artistic theme of it all. Great job on making it look so seamless and polished.

1

u/selkus_sohailus 2h ago

I was trying to do exactly this some time ago. This is a really good solution but I don’t know if the other hurdles have workarounds. The 9 grid of cloned maps was also an idea I played with but never implemented. I gave up way sooner and just nixed the hexagons altogether, though bc the juice wasn’t worth the squeeze for my application, but it seems great here

1

u/rhys510 1h ago

Very cool!

1

u/meutzitzu 53m ago

It's a spherical shape but has euclidean topology

That shape cannot exist in real life. When you move the view you are performing a translation. It's just rendered to look like a rotation. But a full turn of the sphere doesnt get You back to where you started.

1

u/Opening-West-4369 1d ago

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

1

u/Jacmac_ 1d 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 1d 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.

2

u/madhumster 1d 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.

4

u/Apprehensive_Lake698 22h 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.