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