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

Look at active camera

Discussion in 'VR' started by Deleted User, Sep 19, 2018.

  1. Deleted User

    Deleted User

    Guest

    Hi,
    I have an application in Unity using VRTK and a Vive and I added a second display which basically just renders the scene from above, to enable viewers to follow the player.

    I have some objects in the scene (specifically tooltips on objects) that per default face the player - these objects unfortunately aren't well visible in the "viewer" window, as they are facing the HMD and not the viewer camera.

    So I dug a bit into Unity's functions and found a promising one called
    Camera.onPreRender


    I added the following lines to a script in the scene:

    Code (CSharp):
    1.  
    2.     void Start() {
    3.         Camera.onPreRender += PreRender;
    4.     }
    5.  
    6.     public virtual void PreRender(Camera cam)
    7.     {
    8.         foreach (var obj in objects)
    9.         {
    10.              obj.LookAt(cam.transform);
    11.         }
    12.     }
    13.  
    Unfortunately this makes the object face exactly the other camera! Do I just understand the documentation wrong or is this a bug?

    tl;dr: I am looking for a function that makes an object face the currently rendering camera.

    Thank you,
    jp
     
  2. Deleted User

    Deleted User

    Guest

    Are you sure your cam property points at the "good" camera?
     
  3. Deleted User

    Deleted User

    Guest

    Well, as there's not too much information about that, I'm not sure.

    But looking at the example provided (unity docs) it seems to me, that cam does point to the camera that is about to be rendered, yes.