Seamless portals into other spaces

Portal in Lego

Not trying to make a replica of Valve’s Portal, just very curious about the technique behind the solution of seamless teleportation between one space to another. This could surely be done in Unity (graphically with cameras and rendertextures and technically with trigger areas to ghost through a bit of the wall), but what happens codewise when the player goes through a hole in one location to wind up on the other side of the hole without glitches in between (so all view angles of entry/exit seem seamless)?

Would it be a good idea to duplicate the room so there are two rooms at all times or is this just a position arrangement of the player? Once entering the entry portal you immediately transform the position to the exit portal with the same view rotation as when the entry were made. One thing to bear in mind is the cameras near clipping as you get really close to the wall on entry.

As this could be used for other technical reasons in a game the solutions are very interesting to discuss. How would you solve a seamless portal?

I am an author of “Portalizer” package that you can find in AssetStore. Here is explanation of how i made a seamless portals for teleporting objects and FPS (pakcage include only object teleporting).

  1. Rendering: i look into MirrorReflection shader and script that you can find in Wiki. I have add two mirrors on scene and my goal was to render Reflection for camera that look on other mirror. I have modified transformation matrix that know relations between 2 portals and voila, all works fine.

  2. Object teleporting: i have add inner trigger zone to portal which activates when you add moving object here. It simply create clone of this object and add script to it, that control his position and rotation using similar transformation matrix (like in previous step)

  3. I have add a few zones to portals that send info about colliders to global script that manage them (enable|disable collision with walls, other objects e.t.c.)

  4. To make object culling visually when it is inside portal, i have used interesting shader that i found on forum written by Aras. I modified it and got cool result, now my portals are connected and can seamless teleport object.

  5. FPS teleporting: This is the most tricky part. How to teleport camera? I thinking about it too much and here is what i get. To make Camera looks fluid, i played with “Depth only” option. When i am creating clone for FPS, i also create Eyes for it, with absolutely the same params as your MainCam with rotation and position multiply on transformation matrix. Then i “wear glasses” while going through portal. This is basically a plane with transparent shader placed in front of camera. Then i placing projector behind each portal that project “Depth only shader” on this glasses and mix 2 camera views automatically.

You can try my final project here. Good luck

I used portals (black holes) for my “AstroNut 3D” game.(plug!) The player is able to jump from one location to another of the same level (room).

My character had a rigidbody attached to it and moved by Rigidbody.AddForce so what I did was when the player hit on black hole, The direction and speed of the character is stored in varibles, then an animation plays of the character flying in the black hole and the camera flew over to the other black hole, the position of the character was moved to the second blackhole and an animation was played for the character coming out. Then the stored velocity’s direction and speed is reapplied to the character so that the player knows where he/she is flying once they came out of the black hole allowing them to plan on which direction to enter it from.

People are not able to look in the portal but if you need a portal you can look into and see the same thing thats happening you could
use a camera in that location and then render to texture on a plane thats in that same location. But you would need Unity Pro
Depending on your situation it might just be as simple as

on collision enter, player position = new position.

Two-line shader handles the viewing aspect, and it works in Unity Standard. Not sure about the stepping through.

I Just finished making the portals from this video Unity3D - Portal tutorial - YouTube
Easy to understand and now with Unity 5 its available to do it with the free version.
Made the portals into a Prefab for my project.