- Home /
seamless portals like in the game portal
The script that I have teleports the player from one object to another with collisions but I'm looking for it to be more like a gateway sort of like in portal where you could have one foot in one and the other foot out the other. Any help or code for this would be greatly appreciated.
using UnityEngine; using System.Collections;
public class Portals : MonoBehaviour
{
public GameObject otherPortal;
void OnTriggerEnter (Collider other)
{
if(other.tag == "Player")
{
other.transform.position = otherPortal.transform.position + otherPortal.transform.forward * 2;
}
}
}
I've though about his in the past and my solution would be the following. You would need:
2 copies of the character, one for the portal entering, and one for the portal co$$anonymous$$g from.
A dissolver plane that dissolves based on an objects intersection.
A render texture for the main texture of the portal, allowing you to see through it and see the other character.
Sync the animators of both characters and position them equally in and out of each portal as the main player moves in and out of it. Use the initial trigger of the player colliding with the portal to enable and disable the secondary player. When the player fully passes through the portal you can initiate the transportation effect and disable the other characrer, OR if you do it properly you can use both character interchangebly, and switch back and forth as needed.
Answer by lunoland · Aug 11, 2016 at 06:10 PM
An effect like this is actually quite difficult and at a minimum might require that you clone and mask part of the character object. It's not the kind of thing you'd be able to ask on here and get a response where someone codes it for you.
If you wanted a portal to show the area on the other side you would need to work with custom shaders, and it gets even trickier in a first person situation moving the camera through the portal. All this stuff is non-trivial and requires lots of knowledge (especially the shader stuff, which can get pretty esoteric).
It sounds like you're just starting so I would recommend making your portal mechanic work within the confines of what you know how to do. It seems like you're on the right track there; If you add an animation for entering a portal that you play when the player collides with a portal, and an animation for stepping out of the portal that you play at the player's new position, it could be very convincing.
If your game absolutely requires a seamless effect, there may be some asset store solutions that might give you what you want, or you can just dive in trying to figure out how to do it yourself on Google. I found a bunch of info in minutes of searching, including this thread: http://answers.unity3d.com/questions/123547/seamless-portals-into-other-spaces.html
Realistically though, I think this will be overwhelming. You're more likely to finish the game and continue learning if you change the scope to be more inline with your current abilities.
Your answer
Follow this Question
Related Questions
Portal between scenes? 3 Answers
Creating portal camera view with render textur 0 Answers
Are overlapping Occlusion Portals (one open, one closed) treated as an opening, or a blockage? 0 Answers
How do I render 2D Sprites partially (side to side teleport) 3 Answers
3D portal effect on plane 1 Answer