billboard rotation around x, y axis

Hello everyone.

I need to create a billboard effect, so an object always faces the camera. Found this code to do so:

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

Works in principle. Problem is, that the gameobject also follows when the camera is rotated around the z-axis, which I fail to find a way to prevent. Looks like I’m missing something.

The sign should not be rotated relative to the pole.

Any tips are welcome.

Thanks,
Michael

you need to take the z axis out of the equation.

Vector3 targetPos = new Vector3(m_camera.transform.position.x, m_camera.transform.position.y, transform.position.z);
            transform.LookAt(targetPos);

Thank you for your answer.
While it didn’t solve the problem, I realized that I did look at the wrong place to find the problem.
It turned out that I set up my model wrong. Fixing this, my original code started working.

Thanks a lot

no problem, I’m glad you found a solution :slight_smile: