Camera.rotation.y flipping

Hello,
I am trying to place an object in front of my camera, facing the camera.
The object should be placed 1.1m in front of, and 0.4m under the camera’s position.
The object should not get tilted by the cameras rotation, and always have it’s up-vector in the Vector3.up direction.

This is what I have currently:
I placed the obj at camera.position. Then I rotated it at y-axis to face the same direction as the camera. After that I translated the object in this direction.

obj.position.set(camera.position.x, camera.position.y, camera.position.z);
obj.rotation.set(0, camera.rotation.y, 0);
obj.translateZ(-1.1);
obj.translateY(-0.4);

This works, but only if the y-rotation of the camera is between 90 and -90 degrees.
If the camera’s rotation is something like 110 degrees, the object gets placed at 70 degrees instead of 110.

So the mistake is probaly in this line:

obj.rotation.set(0, camera.rotation.y, 0);

How can I get the ‘real’ y-axis rotation of the camera (0-360) degrees?

Is your use case related to the following topic?

Yes kind off. But I am only interrested in rotation.y, the object I am rotating should not get tilted in any way, and only rotated around y-axis.
But whenever I set rotation.x and rotation.z to 0, the y-rotation flips at 180 degrees

could this solution work too? …Parent the object to the camera
camera.add(obj);
… No
sorry I didn’t understood

Not in my case I think. I don’t want the object to move with the camera, but I want to place it in front of the camera at a certain time.

To give some context: I’m working on an AR app, and want to place the Object in front of the camera, when the user taps the screen. The object’s position should be 1.1m away, and 0.4m under the camera’s position. Also, the object should be facing to the camera, only be rotated around y-axis.

But at the moment, this only works, if the user doesn’t turn around with his phone more than 90 degrees. After +90 or -90 degrees, the y-rotation of the camera flips, resulting in the object not being placed in front of the camera anymore.

If(camera.rotation.y >= 90*Math.PI/180){ obj.rotation.y = -camera.rotation.y}

Same for < - 90

? Possibly, untested :slight_smile: