Tardis in Unity

The “bigger-on-the-inside” idea has always facsinated me, especially as a concept in a video game. Attempting to break the concepts of reality is intriguing, and can definately engross a player into a world.

If you don’t want to be bored and just want to know details on how I made this skip to the next section. Keep reading if you want to learn about some physics.

This particular breaking of reality is often called “non-Euclidean” geometry, where our reality is based in euclidean geometry, it is what everyone learns in school. It includes things like “parallel lines never meet”, “the angles in a triangle add up to 180 degrees”, etc. It turns out those are all true because they’re done on a flat plane, like a piece of paper. If you try to do these on a curved surface, like the outside of a ball or on a “saddle” (curved one way in one direction and the opposite way in the other direction, like a Pringle), those basics “facts” aren’t true. Non-Euclidian geometry is geometry done in spaces where Euclid’s original rules (which are for flat planes) aren’t true.

That might be slightly confusing but the big take away is non-Euclidean geometry can break the idea of space being linear. One good example would be wormholes, and how they supposidly bend space-time so that if entered you would be transported to a completely different point in space. In this example spacetime is the non-Euclidean surface.

How did I make the “bigger-on-the-inside” effect?

Despite all my waffling about geometry I actually didn’t need to use any of it in the development of this prototype project. Actually building a non-Euclidean space would have been pretty difficult and time consuming. Instead, I just used cheap tricks and duct tape.

This isn’t anything new really. It’s not too different from the Portal games by Valve. Most tutorials on YouTube will give you something similar to that, but what most of them do is use render textures.

In the game Portal the player has to shoot a pair of portals in order to solve a mixture of puzzles.

In-game Screenshot of Portal by Valve. Credit GameSpot.

These portals work by placing a camera at its centre and rending it’s view on the other portal, and vice versa. When the player then steps into the portal the player is teleported to the other portal. This works very well but needs a lot of work to seem seemless.

This method would have also worked for this project with the interior and exterior acting as portals to each other.

I decided to not do this as I had an idea to use stencil masks instead. Using this method the interior is not a seperate location to the exterior instead we just tell the renderer to only render sections depending on a set of rules.

This method works by creating two Render Objects in the Unity Render Pipeline, one for the outside and another for the inside each assigned to a specific layer. The render objects set the compare function for the Stencil buffer for objects on that set layer. All inside and outside meshes are asigned a specific layer, so that when inside or outside they are rendered appropriately. I then created a mesh the size of the door-way and made it transparent, disabled depth-buffer writing, and turned off culling. This allowed to ignore the render objects and allow you to see through the door.

At the point where you enter through the door you pass a collider, and the graphics pipeline compare function changes and you semi-seemlessly change from outside to inside, or vice versa. I say semi-seemless because there is a flash as the graphics pipeline settings are changed. And since the mesh of the interior is actually where it can be seen you have to deal with disabling/enabling collisions else you find bad behaviour.

The first issue of the flash could be solved by having more access to the graphics pipeline. The second issue it more difficult to solve as you have to go through each collision object and disable/enable everytime you leave/enter. This is the main reason why if I did it again I would use the portal method. However, I do believe that this could be a really good alternative to portals for specific cases.

As a prototype it works great, with a bit more work it would appear flawless.