Instable euler angle on Y axis

Hello,

I am having a weird issue while simply making an object straightly look at a point.
Not sure if I missed something or lack of some understanding about rotations.
I am working on Unity 2017.0.1f3, PC x64.

Here is the problem:
I have a Virtual Camera Transform (I don’t use Cinemachine) on which I call LookAt to another object called Vessel at each LateUpdate.
The Virtual Camera Transform is a child of the Vessel’s Transform and following it exactly from behind, localPosition.X is at 0.

At each frame I put my real camera on the virtual camera transform :

Camera.main.transfrom.position = VirtualCameraTransform.position;
Camera.main.transfrom.rotation= VirtualCameraTransform.rotation;

When I look to the rotation of Virtual Camera Transform on the inspector, the Y on the rotation randomly changes value wether to 180 or -180, while the camera seems stable and all ok.

But this becomes a problem when I interpolate my camera to make it follow another Virtual Camera Transform that is looking at the vessel from the front, there it starts flickering.

I am sure 100% the flickering is caused by the random value change of the Yaxis rotation. Because when I slightly move my VirtualCameraTransforms.localPosition.X to anything different from 0, the Y rotation becomes stable, and there is no more flickering…

Do you have any idea how I can avoid this problem please ? Let me know if you need more details.

Thanks :slight_smile:

You need to do the interpolation using quaternions. Euler angles are not suited for looping around (especially when looping on 2+ axis). Quaternion.Slerp() is a nice utility for this.

Hello, thank you for the reply.
I was talking about euler angles to simplify the explanation of what’s happening. Yet, I do already use Quaternion.Slerp() for interpolation when having the problem.

Code, please! :slight_smile: