# Quaternion.Slerp + Quaternion.LookRotation = X axis rotation weirdness

I have a turret that looks towards its target based on a rotation speed on the Slerp function,
on its Y axis only the “head” of the turret moves, like if you were looking left or right with your own head
and on the X axis the Cannon moves up and down, like if you were looking at the sky or at the ground.

The Cannon is a child gameObject of the Head, so this way when the head rotates the cannon also rotates.

The problem I’m having only happens on the Cannon, that gets the X axis rotation changed only.
Sometimes when the values change, for example when one target is destroyed and the turret starts aiming at another target at a different location the Cannon clearly “bounce” the rotation value to the opposite direction before actually moving towards the correct direction.

A visualization of this could be the following:
Imagine you have a bow and arrow, and you have Target A and Target B to aim at.
Target A is to your left, and its on the horizon line.
Target B is to your right, but above you, like a bird on the sky.
Now imagine that you are aiming first at Target A, then you hit it and decide to change to Target B.
For you to go from Target A to B which is a clear change of aiming from left to right, and from middle or straight in front of you to upwards above you in the sky.
The problem is that imagine before you get your bow and arrow upwards above the horizon line you decide first to aim it towards the ground almost to your feet before actually aiming it up to the sky above you.

Here is the code:

``````        RotationHeadHelper = Quaternion.Slerp(
rotationSpeed
);

if (CannonControl)
{
RotationCannonHelper  = Quaternion.Slerp(
TurretCannon.transform.rotation,
Quaternion.LookRotation(TargetEnemy.transform.Find("TargetAim").position - TurretCannon.transform.position, Vector3.left),
rotationSpeed
);
TurretCannon.transform.localRotation = Quaternion.Euler(RotationCannonHelper.eulerAngles.x, 0, 0);
}
``````

The higher the value is for the rotation speed like 1 or 2, the less noticeable this issue is, and if the value is low such as 0.04 then the problem is very noticeable, but the whole point of doing this is to be able to tweak the rotation speed because some turrets will aim faster then others.

Also, if I rotate the whole head to aim towards the target,( I mean to not rotate the cannon separately, in fact not rotate it at all) and change the code to the follwing the problem does not happen(but I really want to be able to rotate the parts separately, so this is not an option):

``````RotationHeadHelper = Quaternion.Slerp(
rotationSpeed
);