Face to camera but rotate around one axis

Hello, I have a little problem here. I need to rotate my object only around it’s Y axis, to face it to camera. I can’t use LookAt() cuz I need to rotate it only by 1 axis.
If I setting up something like

transform.parent.parent.Rotate(0f, 1f, 0f, Space.Self);

it works well, rotating object around it’s local Y-axis. But when I trying change it to rotation by angle it’s starting randomly spin.

Vector3 targetlookvector = new Vector3(Camera.main.transform.position.x, transform.parent.parent.position.y, Camera.main.transform.position.z) - transform.parent.parent.position;
        targetlookvector = targetlookvector.normalized;
        Vector3 currentlookvector = transform.parent.parent.forward;
        currentlookvector.y = 0;
        currentlookvector = currentlookvector.normalized;
        float angle = Vector3.Angle(currentlookvector, targetlookvector);
        if (targetlookvector.x > 0)
            transform.parent.parent.Rotate(0f, angle, 0f, Space.Self);
        else if (targetlookvector.x < 0)
            transform.parent.parent.Rotate(0f, -angle, 0f, Space.Self);

So what can I do to fix this? Or is there any easier ways?

1 Answer

1

Ah sorry. I better learn how to goole. I’ve found answer here : LookAt locked at Y-axis but in local space - Unity Answers