- Home /
Find corner of rotated plane
Hi. If I have a in z rotated plane with the pivot on the upper left corner, how could i find the vector3 of the upper right corner, no matter how big the plane is scaled or how much it's rotated? Thank you very much!
I just did it the way that I created a new empty GameObject and translated it relative to the plane. From that Object i can get the Vector 3.
Answer by robertbu · Sep 23, 2013 at 03:27 AM
Translating an empty game object is workable, but more expensive than it needs to be. A step up would be to place your empty game object in the upper right corner and make it a child of the plane. Then all you need to do is get the position of the empty game object.
An additional step up (and what I would suggest) would be to calculate a local vector between the upper left corner and the upper right corner and use Transform.TransformPoint() to get the position. From your description, I'm assuming this is a vertical plane. So you want the natural size of that plane (i.e. the size before any scaling inside Unity). For example if you created the plane with a size of (1,1), then the vector would be (1,0,0). If you create it a (2,2), then the vector would be (2,0,0). So if the natural size is (2,2), you could do:
var pos = transform.TransformPoint(Vector3(2,0,0));
Transform.TransformPoint() will take into account any rotation and scaling done inside Unity.
[2]: http://docs.unity3d.com/Documentation/ScriptReference/Transform.TransformPoint.html