Part of my GUI is to be a 3D model that rotates. My question is how do I position said model in a fixed location on the screen; I also need to consider different screen aspect ratios and resolutions.
The model is to be positioned in the bottom left of the screen.
I am most familiar with Java, although will accept any language.
Using viewport coordinates is one approach. Viewport coordinates go from (0,0) in the lower left of the screen to (1,1) at the upper right. So you have some coordinate like (.15, .15, 10) where the ‘10’ is 10 units in front of the camera. You can use Camera.ViewportToWorldPoint() to convert this coordinate into a world position. So you code might look a bit like:
transform.position = Camera.main.ViewportToWorldPoint(Vector3(.15, .15, 10);
The one issue with this code is that you will have a bit of wiggle on the horizontal as the aspect changes. ‘.15’ represents a different world measurement for a wide screen than a narrow one. An alternate is to construct your game object so that the point to be anchored is place in the exact bottom left corner. You can do this either by authoring the model this way, or by using an empty game object as a parent for the anchor and then offsetting the visible game object. Done this way you can use (0.0,0.0,10) as your input and have no horizontal wiggle. Again the ‘10’ needs to be replaced by the distance in front of the camera you want to place the object.