Home > Software design >  How to find the corners of a plane?
How to find the corners of a plane?

Time:09-23

I have a plane in Unity that has been moved, rotated and scaled differently on each axis. How do find the Vector3 coordinates of the corners of that plane?

CodePudding user response:

I would put an empty game object at each corner and make all 4 of them children of the plane. Anytime you need to find the location of the corners, add up transform.position of the plane with transform.position of the corner.

Vlad

CodePudding user response:

Every object in unity has Transform component attached to it which has all the translation, scaling and rotation and you can apply all these transformations to any given vector with transform.Transform<...> methods. Default unity plane mesh has size of (10, 0, 10), so calculating its corners in world space would look like this:

var corner0 = plane.transform.TransformPoint(new Vector3(5, 0, 5));
var corner1 = plane.transform.TransformPoint(new Vector3(-5, 0, 5));
var corner2 = plane.transform.TransformPoint(new Vector3(-5, 0, -5));
var corner3 = plane.transform.TransformPoint(new Vector3(5, 0, -5));
  • Related