0
\$\begingroup\$

I am scaling my world space UI element as my camera go far away from UI using this code snippet:

public class ZoomNamePlace : MonoBehaviour
{
    //public CameraController camContrller;
    public int Zoom_Factor;

    void LateUpdate()
    {
        Zoom();
    }

    void Zoom()
    {
        float size = (Camera.main.transform.position - transform.position).magnitude;
    }

}

It is working fine and my UI scale according to the distance of Camera and UI. Now i want to rotate/billboard my world space UI to the camera and here is my script:

public class Billboard : MonoBehaviour
{

    //Orient the camera after all movement is completed this frame to avoid jittering
    void LateUpdate()
    {
        Camera m_Camera = Camera.main;

        transform.LookAt(transform.position + m_Camera.transform.rotation * Vector3.forward,
            m_Camera.transform.rotation * Vector3.up);
    }
}

But the problem is instead of billboard my UI shape stretched too much maybe due to my canvas scale set to 0.01.

\$\endgroup\$
  • \$\begingroup\$ Can you show us what this looks like in your scene? \$\endgroup\$ – DMGregory May 9 '20 at 11:41
0
\$\begingroup\$

You can use this script to enable a very strict billboarding, hopefully it works for you. Just attach it to the UI objects that should have this behaviour.

public class MyBillB : MonoBehaviour
    {
        private Transform cameraTrans;
        void Start()
        {
            cameraTrans  = Camera.main.transform;
        }
        void LateUpdate() 
        {
            transform.forward = cameraTrans.forward;
        }
    }
\$\endgroup\$
0
\$\begingroup\$

When you parent object transform scale is not uniform (set to 1) then rotating the child object will deform the mesh. So Make sure your parent scale set to 1. In my case my canvas size were set to 0.01 and when my child object rotate its deform the shape.

\$\endgroup\$

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.