How to position 3D object to the camera screen in unity

Viewed 1058

I have a project that deals with AR, so I use ARFoundation in Unity. Everything works fine until I want to position my 3D object on the left of the screen. I tried many solutions but none of them work. I try taking the width and height of the screen and alter them then set the position of my object to them but it didn't work.

What should I be doing?

1 Answers

Understanding the space you are working in is crucial.

Screen positions are a different dimension compared to the normal 3D you have in your scene. In order to exchange positions you need to use https://docs.unity3d.com/ScriptReference/Camera.WorldToScreenPoint.html and https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html.

For example you can have a box that has its transform at 0.0.0 but depending on where you are looking at it and at what angle, it's transform stays the same but its *screen-position changes.

Using WorldToScreenPoint can tell you where the object from the scene is at your screen (2D), and ScreenToWorldPoint does the opposite (you give it 2D from you screen and it gives you that position in the 3D).

Related