Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Getting the vector directions that correspond to the direction of the frustum planes

Discussion in 'Physics' started by louisXV, Jan 25, 2016.

  1. louisXV

    louisXV

    Joined:
    Oct 8, 2015
    Posts:
    10
    TL;DR: Hi all! I have been struggling with the following task: how can I find out the vector directions that correspond to each of the perspective camera view frustum planes?

    A bit more detail:
    So, if Camera.main.transform.forward is the forward direction of the camera, let's call the 4 planes going out from the camera as the top, down, left and right planes (in relation to the current orientation of the camera). I need to shoot rays along the planes and for that, I plan to use:

    Camera.main.transform;position + plane_direction * given_length

    But I don't know how to find the "plane_direction" that corresponds, for instance, to the direction that the top plane forms from the camera position.

    Can anyone help me on that?
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,430
    You can get them with Camera.ViewportPointToRay.
    Geting the rays at the middle of the screen edges gives you a ray (point + direction) along the frustum planes.
     
  3. louisXV

    louisXV

    Joined:
    Oct 8, 2015
    Posts:
    10
    Thanks for your reply! So, I see what you what you are suggesting. I didn't know that ViewportToRay cast rays automatically in those directions. I thought it did it to the forward direction of the camera.

    I will give it a try this afternoon.
     
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,430
    The intended goal of ViewportPointToRay is to point at 3D objects existing at the scene based on a 2D position on the screen (a typical usage is point & click objects in the scene). The side effect is that the edges of the screen represent the exact frustum planes ;)