Search Unity

Portals in Unity

Discussion in 'Scripting' started by Studio_Akiba, Jan 4, 2015.

  1. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I am trying to achieve a similar effect to the portals in ...(you guessed it)... Portal.

    This is something I am willing to spend a lot of time on, and I DO have Unity Pro, pre-order for 5, so I also have 4 for now as well.

    I need the ability to not only create visual portals and be able to seamlessly move between them (NOT teleporting), but also the ability to put objects through them and preferably the ability to snap them to specific places and make sure they don't work on some materials.

    Yes, this is a lot of work, but I am willing to do what I can to get this up, and will be more than willing to share what I do with anyone who can help me do this, my hope out of this is to create something as close to the effect and functionality of Portal and probably release it, I may end up selling a supped-up version of what I manage to come up with on the Asset Store, and all code used that was not provided by myself, the supplier will be mentioned in a commented out line above their code.

    I am hoping this will be a large collaborative effort by many people and rest assured, I will NOT be selling your code at all, if this ever ends up on the Asset Store it will most likely be free, or rewritten completely, to which anyone who helped me with the original would only have to ask to be given.

    If you are interested in helping with this, I am always reachable on the Unity Forums, probably easiest to post a reply to this thread.

    Thanks.
    Kyle Briggs.
     
    BenZed likes this.
  2. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
  3. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    UPDATE: Our website seems to be experiencing some issues at the moment, we are currently talking to the hosts and waiting for them to get back to us, we hope this will be fixed soon.
     
  4. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Until our website is back up and running, here is a more in-depth overview of what Project Physix is:

    Project Physix was started as a community collaboration project on 4th January 2015 to supply users of the Unity 3D Game Engine a high-quality and free solution to portals.
    The aim of this project was to replicate the effects and functionality of the portals within Valve's Portal and Portal 2 video game titles.



    Disclaimer: This project was in no way designed to infringe on Valve's IP (Intellectual Property) rights. The majority of code was supplied by the community.



    This page will be updated regularly with our latest progress and assets. This is an open source project and we have no intention of withholding anything from the amazing community that helped us with this project.
     
  5. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    This sounds like a great project. I know you can do portal-ish type things with layers, but things often get sticky at the actual portal itself, especially if you want to be on one side and affect the other, or if you want to be one foot on one side and one foot on the other.

    One effect I'd like to see is sort of a cartoon-like effect where you lay down a hole and then a character emerges from it.
     
  6. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    We will make this project as adaptive as possible throughout its development, which I'm sure will take some time, but I am hopeful that this will be usable for more than just portals.

    With this project I hope the community will do what it always does when something new and exciting is released, modify it and make it better, that's why I am hoping to have others contribute to this.

    I have sent a message to the developer of this demo, I am hoping he may be generous enough to provide us with the effect he is using for his portals.



    I am hoping to take this kind of thing one step further, as you have described, instead of teleporting the player on collision, I am hoping we will be able to collectively come up with a solution that allows for seamless transitions, like those seen in Portal, where you can stand in-between them and see through both, as though there was a physical hole there.
     
  7. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    In portal it is not seamless, the portals just each have there own camra that renders to the opposite of the portal pair. Than when moving through a portal you maintain your velocity.

    You are never actually on both sides of the portal at once as far as the game logic goes, it just appears that way since you can walk into the wall a little, and you teleport when the charcter center collides with it. Add that with the render texture stuff and it fakes it very well.

    Edit: don't forgot to change the players camera angle when going through the portal, and the cameras to render the texture for the portal are a little more complex since there rotation would have to change as well based on the player position
     
    Last edited: Jan 4, 2015
  8. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    I know zero about shaders, but I've wondered if it is possible to have a character appear to be astride a portal by using a variant of a dissolve shader to render part of the character on layer A and part on layer B, or failing that, to have a means of coordinating a dissolve such that two identical models in the same space but on different layers are dissolved one into the other based on an incrementing/decrementing value on a X, Y, or Z axis.
     
    Last edited: Jan 5, 2015
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Not sure what the fuss is about. With pro the portals created in the game Portal are not that difficult to make. Portal became popular because of its unique mechanic, and the well executed gameplay. Its not because implementing portals is particularly difficult.

    Thoughts on the implementation of portals
    • Use a render texture to see through the portal
    • Use custom controller and rigidbodies on anything that needs to move through the portals
    • Duplicate the mesh of anything that moves through the portal to have it appear on both sides. For performance it probably pays off to create the duplicate mesh from the start of the game for every object that can go through a portal
    • Use collision detection to detect when an object is going through a portal. Put the fake mesh on the other side. Rotate anything that goes through the portal to match to orientation of the new portal. Move the actual object through when some defined pivot point (probably its actual transform) passes the plain of the portal. At this point the object and its duplicate mesh should change places. It should also become subject to the physics from the other side of the portal.
     
  10. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    And if someone wants scripts that basically repeat what was done in Portal, here's a set of scripts someone posted: https://drive.google.com/file/d/0B2lkEEFpyGuBcllDYjVCZXhoX2s/edit

    What I'm looking for is Portal-like, but preferably able to operate with Unity Indie and with portals in mid-air, where a body doesn't teleport but visibly transitions through a portal surface.
     
  11. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Creating the body visibly passing through the portal isn't too difficult in free. Making the portal show an image of what's on the other side is difficult. So you could easily make a StarGate for example. But making a Portal would be difficult.
     
  12. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    @BoredMormon
    I have made a "Stargate" effect many times for different purposes, this I have found quite easy, its being able to place them at will, see through them and disable them if necessary that I have never touched before.

    After hunting around, I came to the conclusion that there is nothing to the kind of quality I am used to working with so I decided to start this, I am hoping that more people will get involved and we can start working on this as soon as possible.
     
  13. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    It almost interesting enough for me to give it a go. However I don't have pro, so I'm not sure how useful I'd be.

    Good luck!
     
  14. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    @BoredMormon
    If you are talking about missing Unity Pro for Render to texture, check this out.
    Not sure how useful it will be, but may be worth giving a go.
     
  15. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    I can't think of any instance in which I have seen this effect displayed. Anybody have a reference they can show?

    To be clear, I'm speaking of a skinned mesh body that passes partly into and then through a portal, not a camera that travels through a portal.
     
  16. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    @hopeful
    Both Portal titles have this effect in I believe, although I may have misinterpreted what you are talking about.
     
  17. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
  18. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    I've not played Portal, but from what I see of it, if you play it in 3rd person it blinks you through the portals. You don't ever appear to be half in / half out of a portal. You don't, say, stick your hand in one portal and see it coming out of another portal.

    Am I mistaken?
     
  19. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Portal was never really designed for 3rd person, Valve developers use this to test the character model in their games.
    In first person perspective, with portals close to each other, you can see the body emerge from one without it being fully through the other.

    It is not something most people notice, and for this project we will be focusing more on functionality than aesthetics until more of the community gathers interest and works out how to modify it.

    We are hoping to have our first little demo working in the next week or so, until then we will be concentrating on getting it roughly working, and then concentrate on fine tuning later after our first demo and release the code and see what people can do with it.
     
  20. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    In Portal, the portals all appear to be cast onto walls, thus a body passing through a portal is actually entering or exiting a wall, and this is what creates the appearance of crossing a portal boundary.

    If the portal was in mid-air, I think it might be more difficult to show just a portion of the body as it enters or exits a portal.
     
  21. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Kinda with some shader trickery it is possible to alpha blend out a mesh basded on a user defined plane and normal.
     
    Kiwasi likes this.
  22. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    If something like this exists, it seems like it would be fun to have one.

    I already have Dimensions & Portals, an inexpensive plugin which enables most of the portal type effects on indie.
     
    Last edited: Jan 6, 2015
  23. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    @hopeful
    I have looked at the dimensions and portals asset several times and kept a close eye on it and the biggest problem I have with it is that the player falls through the floor or it doesn't work at all when trying to use portals on the floor, at least that's what happens in the demo which is quite old now, let me know if this is fixed how, I'd be very interested if portals could be used on floors, I may consider getting it just so we can see how it works.

    Today I will be working on the portal edge effects, this shouldn't take long, if anyone can work out how to rotate a UV with an illuminated shader, this would be very useful as the portal is currently 1x2 units, and the effects will most likely be a stretched round image on a plane, rotating via UV would be required for this approach.
     
  24. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    In general, it seems to me that falling through the floor in the D&P demo should be something that's just an error in the demo and not part of that system. The system is about creating portals you can see and move through, and in general the magic is done with layers. When you are using a portal in D&P you are passing from one layer to another, and in my opinion it's a very nice system. Inexpensive, too.

    With that at hand and with you having Pro and probably an abundance of Portal-esque scripts on the internet (like the set I linked to above), I'd think you'd have everything you need for your solution if you are planning on having portals cast on walls.

    I'm not sure if you're looking to buy anything from the store, but this asset might be a possibility depending on what you're looking for regarding portal effects.
     
  25. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    If someone can confirm that this bug is NOT in the release, I will consider it as an option for this project, it is also worth noting again that this project WILL be free on release so any community members who want to pitch in, need only ask!
     
  26. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Very cool!
     
  27. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I am testing out the Dimensions and Portals asset for ideas, and the demo scene doesn't work, I can place portals but not walk through them, and in my own scene, I cannot even successfully throw a portal, I have followed the documentation several times to the letter just in case, and no luck, anyone else had this problem in a new project?
     
  28. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    It all used to work. Best to contact the dev for it (by PM) if it is failing for you out of the box.
     
  29. Barachiel

    Barachiel

    Joined:
    Nov 25, 2012
    Posts:
    147
    Out of passing curiosity I picked it up to have a look at it a few months back. Unless something has changed since then, the demo scenes it came with worked fine but there were issues getting it to work in a fresh scene. After some digging around and talking with other people, it looks like it was a bug.
     
  30. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I have it working now, sort of...
    Portals on the floor still do not work, I have sifted through the code quickly to look for collision problems but I can't find any reason why I can't use a portal on the floor, the player just doesn't go through them.
     
  31. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I will also be looking for textures to use with this pretty soon, I am about to package up all the textures I have created so far, I am hoping someone here can give them a less sterile look, these textures will eventually be provided with the free release of this project, and the editor will be given full credit.

    I am looking for a more "Overgrown" style to them, think Portal 2.
     
  32. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    I'm guessing it's a floor layer problem related to the character controller ...?
     
  33. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
  34. Barachiel

    Barachiel

    Joined:
    Nov 25, 2012
    Posts:
    147
    Though I think the focus should be primarily aimed at getting a working prototype up and running before worrying too much about how it looks, I'm curious as to whether you plan to use an animated texture or sprite, use particle effects, or some combination of the two.

    As far as the camera goes, you can't simply render the view from the other portal, or even just have it's view rotate along with your own. It comes out really wonky that way. You need to adjust the matrix of the camera.
    Docs for this are here: http://docs.unity3d.com/ScriptReference/Camera-projectionMatrix.html
     
  35. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    For the portals themselves, I am planning to use a particle effect for the emitted glow around it, and a custom shader that rotates a texture to add the "whisp" effect around the portal, hiding the edges.

    This may change throughout progression of the project but I feel this is the best and most efficient way to do this.
     
  36. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    If anyone can work out how to rotate a transparent material, it would be VERY useful, I cannot find anything that supports transparency, or that rotates from the middle strangely.
     
  37. Barachiel

    Barachiel

    Joined:
    Nov 25, 2012
    Posts:
    147
    Are you talking about rotating the texture on the material, the same as you can give it an offset?
    What material do you need to rotate?
    Are you trying to rotate it over time for animation purposes, or just to adjust it?
     
  38. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    I'm talking about rotating the texture in a material, I need to do it from the center preferably for this method to work, making particles go in a circle and then stretching it to 1x2 isn't easy so I'd rather do a lot of the styling with this method.
     
  39. sspence

    sspence

    Joined:
    Aug 22, 2017
    Posts:
    1
    Hey folks. I'm the author of the google drive scripts mentioned here:

    https://forum.unity.com/threads/portals-in-unity.289038/#post-1908199

    However the old Google Drive link is bugged, and spamming me for permissions, even though I set and now re-set it to viewable by anyone. Instead, I try to keep an up to date link here. When I return from a work trip, maybe I'll just move hosting the tiny zip to my personal website...



    I'll be adding a filter to automatically delete these Google Drive spam emails now. Toodles!
     
    hopeful likes this.
  40. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    My approach is generally to Export a .unitypackage from Unity and attach it to your message here. That way there is zero external dependency plus you can update it anytime you want.

    Just say "No" to creating needless external and third party dependencies. The world has enough of those.
     
  41. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,999
    While unitypackages are great for packaging stuff between projects, I don't really like them for sharing. packages can contain bad code and it's difficult to look at it before actually importing and at this time it's already too late :) Putting stuff on github is usually the best approach.
     
    Kurt-Dekker likes this.