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

Question Casting rays from object with camera perspektive angle (fov)

Discussion in 'Scripting' started by Pohlerbaer, Mar 15, 2022.

  1. Pohlerbaer

    Pohlerbaer

    Joined:
    Mar 8, 2022
    Posts:
    7
    Hello guys!

    Currently I'm working on a project, where I get positional data from a camera sensor, which is placed on a ceiling. It's able to detect, if something touches the wall and gives that information back to me.

    In the end, a projector on the wall should show the game view, and make everything interactable, just like a giant touchscreen. I managed to extract the positional data and convert it to Unity so it currently looks like that: Capture.PNG Capture1.PNG
    (The red ray drawn is my hand touching the wall)

    So far so good. The problem I encounter is, that by shooting the ray straight forward, the perspective view of the camera doesn't get covered at all. Currently the sensor acts like an orthogonal camera view.

    The question I have is, how it would be possible to shoot out the rays at an angle, to cover the whole fov of the camera, like this for instance: Capture3.PNG

    Thanks for your help in advance!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Where are you getting the ray from? If you get it from the Camera API, it will give you an appropriate ray. Check in the Camera docs for calls containing the word "ray"
     
    Pohlerbaer likes this.
  3. Pohlerbaer

    Pohlerbaer

    Joined:
    Mar 8, 2022
    Posts:
    7
    Hey, I already got it to work. The way I fixed this error, was by offsetting the ray origin, to the camera position, and shooting the ray in the direction of the point where the sensor recognizes a touch!

    Now everything works just as intended :)
     
    Kurt-Dekker likes this.