Search Unity

Portals and rotations

Discussion in 'Scripting' started by kaamos, Mar 22, 2017.

  1. kaamos

    kaamos

    Joined:
    Aug 6, 2013
    Posts:
    48
    Hi! I'm in the process of quickly prototyping a fairly simple portal system, and though it's mostly working, I'm struggling with getting the portals to behave correctly irrespective of their rotation. I'm using the following code to manage the portal cameras (excuse the messy code, I just want to prove the concept at this stage):

    Code (CSharp):
    1.     void portal_1_update()
    2.     {
    3.         portal_1.transform.localRotation = player_camera.transform.rotation;
    4.  
    5.         temp = portal_1_root.transform.position - portal_2_root.transform.position;
    6.         temp += player_camera.transform.position;
    7.         portal_1.transform.position = temp;
    8.  
    9.         temp = portal_1.transform.localEulerAngles;
    10.         temp.y -= 180;
    11.  
    12.         portal_1.transform.localEulerAngles = temp;
    13.      }
    The problem with the above code (amongst other things) is that the portal cannot be rotated away from 0,0,0 without breaking the way the camera renders the other side. Any help would be appreciated!