Hey, I am jelle and after making a bunch of2D and 3D games, I was ready for the next step.
Now what is there beyond the 3rd dimension? Well, the 4th dimension of course! Get ready for some hyper dimensional travel! (Intro) You may say, Isn’t the fourth dimensionjust time?? You could look at it that way, But that isnot what I mean.
We all live in a 3 dimensional world wherewe can move forwards, backwards, left, right up and down, or in other words: along theX, Y and Z axis.
Three perpendicular directions that can describeevery place in our universe.
What if… There was a fourth axis that we could movealong, perpendicular to all 3 other axis: a W-axis.
And define objects with those 4-dimensionalcoordinates Of course, We simple humans can’t perceivethese objects fully, but what we can do is look at some sort of 3D projection, or sectionof those objects.
There are a number of different ways to visualisethese 4D objects.
One very practical and useful way is to createa 3D section of the 4D shape, similar to what the upcoming game “Miegakure” does.
To understand this, I had to get to the sourceof this concept, A short novel named: Flatland.
Flatland tells the story of a 2 dimensionalbeing trying to understand the 3rd dimension.
So you are living on a plane and are tryingto grasp the concept of a 3D object, in this case a sphere.
The only thing we can see is the 2D sectionof that sphere, so a circle.
When the sphere moves along the 3rd dimension, all we can see is a growing and shrinking circle, until it suddenly disappears.
By layering all those sections we can kindof understand what a 3D sphere could look like.
From there we can use the same way of thinkingfor the 4th dimension.
So instead of taking a 2D section of a 3Dobject, We can take a 3D section of a 4D object.
I could create a 4 dimensional object, andthen set the w axis to a certain value, the resulting shape would then be something thatcould be displayed with the 3 remaining axis.
Now, how was I going to create this abstractgeometry and how was going to put it in a game, where all I have is a mathematical equationthat defines its shape.
If only I created something that does thatexact thing but with some other kind of mathematical functions, I don’t know something like:Fractals.
We’re going to use ray marching again! For those of you who need a reminder or havenever heard of ray marching, a ray marcher is a rendering method that draws shapes basedon distances from the camera.
Those distances are defined as formulas.
So What I had to do is define the objectsAs 4 dimensional formulas and let the camera make a 3D section of those shapes at a certainW position.
Tadaa: my first 4D object, a Hypersphere! Well it looks like a regular sphere but theradius of the sphere is not just determined by the x, y and Z direction, now there isa W axis a well.
So if we move our w position with a slider, we can see the sphere growing and shrinking, just like the 2d equivalent earlier, wherethe circle grows and shrinks when we move the sphere back and forth.
Of course none of this looks very exiting, it’s just a round thing that grows and shrinks.
The cool things start when we create otherobjects like a Hypercube and rotate them as well.
Because we Are now creating 4D shapes, wesuddenly have 3 more rotational axis we can play with, the xw, yw and zw planes! Aha, this looks promising! Let’s create some more shapes like a duocilinder, a 5 cell and 16 cell ! Placing these elements in the scene wasn’tvery easy with my old ray marching script, so I gave it an update similar to how Sebastiandid it in his video, where each object can be placed with an empty game object and ascript attached to it.
Of course I had to give it an upgrade to allowthe 4 dimensional movement and rotation by defining those in the inspector.
Now placing objects was as easy as click anddrag! Wonderfull.
There was one problem tough, The rotationdidn’t seem to work the same way as in the inspector… I dug into some unity meta code and realisedthat the order in which the rotations are applied is very important, so after switchingthose around.
The rotation did what it had to do.
I was getting exited and placed way too manyobjects in the scene, resulting in terrible frame rates.
I hadn’t even created a single level yet, and I was already pushing the game to it’s limits.
So I needed some way to optimise all of this:Then, I remembered that the performance of ray marching is heavily dependant on the resolutionof the game.
If I could lower the resolution, without havingit look like a dirty low res game, The game would run much smoother.
That reminded me of a beautiful indie gamecalled “A short hike”.
That game was rendered at a very low resolutionto get more of a pixelated look, while still remaining a full 3D game.
So, I just did the same thing! I let the camera render to a low res rendertexture and set up a second camera that would look at that rendered texture.
badabing, badaboem, 4 times the frame rate! This meant I had to keep everything very simpleand clear, I had planned to use my little astronaut from one of my previous games, andhe was in need of an upgrade to withstand travelling through the 4th dimension, so Idid! A Nic big neck brace! We wouldn’t want a whiplash! I added a cell shader so the colors wouldbe better defined and more clear.
I also created an invisible capsule that followsthe player around to cast a shadow on the ray marched objects.
To decorate the scene, I added some 4 dimensionaltrees and rocks.
The ground plane was given a waving patterncontrolled by a sin wave that was defined by all 4 axis.
So moving W axis would create cool wavy effects.
Because all the shapes were raymarched, Icould very easily apply boolean operators on them, like union, intersect and substract.
Allowing me to create more complex shapes! Like floating islands! Which were various objects intersecting withthe 4D planes.
This gave me a great idea for the gameplay.
Let me explain: You play as the little astronaut who wantsto get back to his ship! But there are of course numerous obstaclesin the way! Luckily there are these convenient buttonsin place that let you turn certain objects into a different boolean operator, so forexample, that cube that is blocking your way, could suddenly become a hole to get through! I created a button and an orb that you couldplace on the button.
However, the orb also lives in the fourthdimension, so the button would only be active at certain w locations, with you can see abovethe slider.
This created many opportunities for cool puzzles! Like a doorway that would appear or a slopethat would change shape and become its inverse.
I created 8 levels in total, each of thembuilding on the previous one, but all with the same goal of getting to your ship! You have to traverse the world and look forpathways throughout the fourth dimension by moving the slider.
If you don’t see anything, it’s probablysomewhere along the 4th dimension! I added a start and level select screen, andwith all of that the game was done.
I released the game on Itch.
io and you canplay it now for free, I’ve also added the 4D framework on GitHub so you can make yourown 4D boolean games! Be sure to like the video if you enjoyed thisjourney into the 4th dimension and subscribe if you want to see more in the future.
And I’ll see you guys next time, where Iwill contemplate the meaning of life.