1
\$\begingroup\$

How do i get a plane to always face an object with the flat/mesh/xy side? I tried sticking in Vector3. forward and up but i always get the plane facing the object on an edge.

    void Update()
{
    planeRotate.transform.LookAt(cube.transform, );
}

enter image description here

\$\endgroup\$
1
\$\begingroup\$

The face of a plane primitive points in its local "up" direction (y+), not the local "forward" direction (z+) used by LookAt.

So you want a rotation that takes the y+ axis to point toward the target:

Vector3 directionToTarget = cube.transform.position - planeRotation.transform.position;
planeRotation.transform.rotation = Quaternion.FromToRotation(Vector3.up, directionToTarget);

If you have a preferred "twist" direction you want the z+ axis to face, you gan enforce that like so:

Vector3 zTarget = Vector3.up;

Quaternion zToTarget = Quaternion.LookRotation(directionToTarget, -zTarget);
Quaternion yToZ = Quaternion.Euler(90, 0, 0);

planeRotation.transform.rotation = zToTarget * yToZ;
\$\endgroup\$
1
  • \$\begingroup\$ how do i stop it from tumbling around, stop it from rotating around y+ while it rotates to face the cube? \$\endgroup\$
    – mavish
    Aug 9 '20 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.