Search Unity

Trigger an action on or off based on camera direction

Discussion in 'AR/VR (XR) Discussion' started by eco_bach, Mar 13, 2019.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Trying to figure out how I would trigger an action on or off based on the camera direction in an AR application. Essentially when an object is in the center of camera view it should activate and when it leaves the camera frustrum it should deactivate.

    Would this be done via Raycasting or?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    You would use Camera.WorldToViewportPoint, and look for x and y both near 0. Also check that z > 0, as z < 0 indicates the point is behind the camera (IIRC).
     
  3. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Thanks!