Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Creating an effective portal system?

Discussion in 'Editor & General Support' started by ubunturox104, Mar 24, 2016.

  1. ubunturox104

    ubunturox104

    Joined:
    Mar 24, 2016
    Posts:
    7
    Aloha,

    I am starting to work on a 3D game using the Unity engine. Although I am not trying to make a clone of Portal, I am interested in trying to create a portal system like the popular video game title. I have seen some demos and some tutorials, but the portals are either weird-looking or there is no actual tutorial or downloadable script I can modify and use (the demos have what I want, but there's no link :(). Also, I discovered the Portalizer asset, but found that it's deprecated and therefore not purchase-able. I already tried to contact the creator on Unity Answers and via email, but he didn't give me a response. Is there a way that I can create an effective portal system?

    Attached is a link of what I want to achieve:
     
  2. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I'd say use a Render Texture for the actual portal, then teleport the player to the position and rotation of the object when you get to it so you seamlessly transition to the portal location.
     
    Kiwasi likes this.
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,617
    Well yeah... but what do you put in the render texture?

    Intuition says it shouldn't be too hard if you understand the math behind transformations and model/view/projection matrices, but there will still be subtleties.
     
  4. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I'd just throw a camera at the part where the portal hits, then have the render texture show the Camera. Doesn't seem like it could be that complicated lol. But then again - I've never tried.
     
  5. ubunturox104

    ubunturox104

    Joined:
    Mar 24, 2016
    Posts:
    7
    Is there a particular script I have to use? Also, how do I do that (I forgot to mention that I'm new to Unity 5)?
     
  6. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,617
    The portals in Portal are perspective correct. As you move around looking into a portal the perspective updates correctly for the new angle, distance and orientation. Just sticking a camera on the other end of the portal won't achieve that.
     
    N1warhead likes this.
  7. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
  8. ubunturox104

    ubunturox104

    Joined:
    Mar 24, 2016
    Posts:
    7
  9. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Simple.

    Code (csharp):
    1.  
    2. P1  P2
    3. |  /  |  /
    4. | /  | /
    5. |/ C1  |/ C2
    6. |\  |\
    7. | \  | \
    8. |  \  |  \
    9.  
    P1/P2 are portals, C1/C2 are cameras. And now. C1 is child of P1 located at (0,0,0) in relation to P1 and oriented the same way P1 is. Same for C2, but is child of P2. C1 renders to RenderTexture that is displayed on P2 and C2 renders to render texture that is displayed on P1.

    I've figured it out long time ago when I've played some portal clone in Unity on Kongregate, except I had no resources to do it as it was still unity 4 lifecycle and I had no render textures..
     
  10. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,554
    Calculate (eye) camera position relative to portal (the one you see).

    Put the other camera - fake camera - relative to the other portal, using the same offset.

    Render what THAT camera sees to texture, and stick the result onto original portal using screen coordinates as texture.
     
  11. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,617
    Exactly.

    The subtleties will be things like what to do with other stuff that appears between the correctly transformed portal-view camera and its portal, and how to handle recursion when portals can see other portals.
     
  12. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
  13. ubunturox104

    ubunturox104

    Joined:
    Mar 24, 2016
    Posts:
    7
    That does look cool, but it looks like there's no way to manually place the portals via a portal gun. Is there a way to implement a portal gun for that?
     
  14. Eudaimonium

    Eudaimonium

    Joined:
    Dec 22, 2013
    Posts:
    131
    Yes, because building portals like in Portal game is actually incredibly, deceptively difficult problem to solve.

    I have actually took up the challenge of directly replicating the portal mechanics out of Portal game (beating the Portalizer pack because AFAIK it has some minor collision issues), and so far I got the rendering pretty much done (except for some border cases in relative portal orientation where oblique frustum calculation for the camera goes tits up):

    Portals.jpg
    Oblique frustum culling out green boxes which would otherwise get in the way of portal camera:
    Oblique.jpg


    I haven't yet gotten around to actual teleportation mechanics but they should not provide TOO much trouble.

    I am really sparse on this project lately but I do intent to finish it and release it on Asset store, however don't hold your breath for it. I'm looking to release the basic portal functionality for free, plus a payed version with a collection of fancy shaders for portal "ripple" and "glow" effects or some extra sound effects of my design or a portal gun or such :p

    By the way, do notice that in your example video in opening post, the player is careful to actually avoid walking through the portal because that's probably not working in their project :D Not that I can blame them though.
     
  15. Deleted User

    Deleted User

    Guest

    For those interested, I have just released my asset free of charge on assets store, with numerous fixes and implementations (and others things that will arrive with the update 1.1).

    Link for the forum

    Link for the asset
     
    Last edited by a moderator: Apr 13, 2016
    chelnok likes this.
  16. Deleted User

    Deleted User

    Guest

    Nope, you can do this with an external script, that scale portal and disable trigger event on it (I have added a specific variable for this) and vice versa. It's not much difficult to make.
     
    Last edited by a moderator: Apr 14, 2016
  17. ubunturox104

    ubunturox104

    Joined:
    Mar 24, 2016
    Posts:
    7
    I've played around with it a little bit and looks promising. What would be the script to add a portal gun? Again, I am new to Unity 5. It's a wonder I managed to get my Adobe Fuse character imported...

    EDIT: Figured out how to import them, link them, and resize them. Now to have them on the wall without collision problems...

     
    Last edited: Jun 8, 2016
  18. Deleted User

    Deleted User

    Guest

    Sorry for being late. However I haven't add a portal gun because when I creating this asset, I was focused to create a generalized package. But you can doing this by adding a mesh gameobject (and this is important), like child of character controller.
     
  19. Little_Narwhal_13

    Little_Narwhal_13

    Joined:
    Feb 6, 2017
    Posts:
    15
    Brackeys made a great portal system where he has a camera next to the other side of the portal, which moves accordingly to the player's position, and then i belive he changes the depth or something and makes t attached to a plane or something, i didnt actually watch it entirely. Still leaves me with the problem of how to make a portal that raycasts can go through, as I would love to have an fps that includes portals...