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. Dismiss Notice

Question How can I move a Gameobject to sit with screen size in AR

Discussion in 'AR' started by Granxdavis, Jan 13, 2023.

  1. Granxdavis

    Granxdavis

    Joined:
    Jun 29, 2017
    Posts:
    2
    Hi, I want to move a Gameobject to fit my ARCamera. I attach the GO to the camera, but it depends on its size, the GO should be further or closer on the Z axis. How can I find this relationship without scaling the GO?
     
  2. davidmo_unity

    davidmo_unity

    Unity Technologies

    Joined:
    Jun 18, 2019
    Posts:
    99
    You will need to find the closest distance Z at which the bounding box of the game object does not intersect against the camera frustum. A simple brute force solution would be to subdivide the space and check to see if the bounding volume intersects the rays representing the frustum edges until they no longer do. A more elegant solution would be determine the rate of change in the farclip plane's area and apply it as a function of Z then compute the limit as the area approaches the area of the largest bounding box face on the game object.