For the past few days, I've been polishing the portals in Relativity, and adding features to them. In addition to having the player move between portals, I also wanted the player to be able to carry objects with them. Getting the basics of teleporting both the player and the objects wasn't so difficult. I was, however, getting this particular problem:
As you can see, the cube that the player is carrying would disappear for a second while going through the portal. The reason why this was happening was because at that moment, the cube hasn't been teleported yet, and is behind the render texture, which is showing the other scene. Teleportation doesn't occur until the player hits the render texture.
I tried a bunch of different techniques to fix the problem, such as teleporting the cube
first, but all without much success. Eventually though, I remember reading somewhere that to get the physics of objects going through portals right in Portal, Valve would actually duplicate an object on the other side of the portal.
This gave me an idea.
I duplicated the player game object, removed all the controller scripts, camera, and colliders, so that only the renderer remained. I then attached a cube object to this empty player, also with is collider and scripts removed. Let's call this the "Mirror Image".
Then, whenever the player was within a specific zone in one portal, I would activate the mirror image in the other portal, with the same local position and rotation as the player. And so, in the split second where the actual cube disappears behind the render texture, the mirror image cube fills in the gap.
Here's what it looks like:
Great read! Thanks for posting!
Thanks! I totally benefited from Valve talking about the tech behind their portals, so thought I'd to the same. It's also a pretty clever solution, if I do say so myself :)
Very clever. In words it sounds so simple but I can guess that the initial implementation was far from simple?
Ya, it was super confusing. Especially because you'd have one portal referencing the other. For example, if Portal A and Portal B are connected, and you're in Portal A, I need the mirror image to appear in Portal B. In the code, I'd refer to the other portal as sisterPortal, and there was a lot of sisterPortal of sisterPortal stuff going on back and forth.
Ah man! Glad you got there though, this post is gonna help a lot of people who may need object-friendly portals in their current / future projects.
Superb work.