- Home /
Screen Coordinates of an object's corners
I'm wondering how to tell where the furthest left and "top" screen coordinates of an object is.
I had thought to use the transform.collider.min and doing worldtoscreenpoint, but as the camera rotates around the object (especially around the x axis) this doesn't always hold up.
Thanks!
Answer by Jaap Kreijkamp · Jun 20, 2010 at 07:18 AM
I'm afraid there's no easy solution for this. You could go over all the points of your collider, calculate screencoords and calculate min/max values on them.
Yeah, that sounds painful. If it can't be done, it can't be done though. $$anonymous$$aybe I'll add a comment about this in the GUI thread at feedback.unity3d.com.
Answer by Auberhine · Sep 27, 2010 at 02:39 PM
If you still havent found an easier solution for this, here is my complicated and not very accurate solution.
This is the function you need for getting an objects PIXEL SIZE (size drawn on screen)
//Gives pixel size of an object
public static float angularSize (float diam, float dist, Camera cam) {
float aSize = (diam / dist) * Mathf.Rad2Deg;
float pSize = ((aSize * Scr.height) / cam.fieldOfView);
return pSize;
}
Where diam is, diam = transform.collider.bounds.extents.magnitude; dist is, dist = Vector3.Distance (transform.position, Camera.main.transform.position); cam is the camera you are using.
This works for square or circular objects best. Then you can work your way through objects screen position and the objects screen size to find your answer.
Regards,
Aubergine
Your answer
![](https://koobas.hobune.stream/wayback/20220613062525im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Game. Screen, Camera and coordinates. 0 Answers
TransformDirection gives the same coordinates as in input 0 Answers
Output second camera to second screen? 0 Answers
How to "fade out" a scene 6 Answers