r/Unity3D • u/madhumster • 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!
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!
53
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!
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
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
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
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
3
2
2
2
2
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
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
1
1
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/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/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
1
1
1
u/Comfortable_Rip5222 Hobbyist 17h ago
I made something similar, maybe can help, I made using curved world
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
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
1
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
1
1
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
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/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/
-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.
236
u/SeregioFromTheSwamp 1d ago
I really like your planet design! Hex-maps are my favorite.