Locking Rotation on Z-Axis Not Working

I want a sprite to always face the camera, except in the Z-Axis. My sprites keep tipping left or right when I move the camera, and I can’t have that.

I have been googling this for hours. I’ve tried transform.LookAt or Quaternion.LookRotation and manually setting the z to 0, but for whatever reason the z keeps adjusting. I’ve seen and tried so many solutions that feel like they should work but just don’t. If it matters, my sprite is a child of another object, but trying localRotation doesn’t work either. Freezing rigidbody constraints also has no effect.

The most accurate I can get it is this:

public class Billboard : MonoBehaviour
    GameObject cam;
    float minDist;
    // Start is called before the first frame update
    void Start()
        cam = GameObject.Find("Main Camera");

    // Update is called once per frame
    void LateUpdate()
        minDist = cam.GetComponent<CameraOrbit>().distanceMin;
        transform.localScale = new Vector3(1f, 1f, 1f) * (cam.GetComponent<CameraOrbit>().distance - minDist) * 1.01f / 3;

        Vector3 rot = transform.rotation.eulerAngles;
        transform.rotation = Quaternion.Euler(rot.x, rot.y, 0);


With this I can get the sprite to face the camera, but the z axis refuses to stay at zero. It feels like this should be super simple but even StackOverflow was stumped.

Special thanks to StarManta for answering this question on the Unity Forums.

"OK, I think I see what’s happening. Them looking like they’re rotated is, I think, an illusion; I think they really are accurately pointing at the camera and right-side-up. But, you’re treating the camera as if it has a round/fisheye projection, when it really has a rectilinear projection. Usually this doesn’t matter but in this case it does. It’s hard to explain exactly how this affects this, but the upshot is that, when things that are on either side of the center of the screen are set to “look towards” the camera, they actually appear to be rotated around their Y axes.

The solution to this is actually annoyingly simple: don’t set the rotation to look at the camera, set it to be the same as the camera."

transform.rotation = cam.transform.rotation;

I’m also trying to find a way to lock the Transform.position in place, for my camera, if anyone has a solution, would love to hear !