Tank urret rotation - Need help.

Hi guys,

for 3 three hours I try to rotate a tank turret now…
And I only get it to smoothly look to the target.
But the problem is how can I fix the Z axis of the turret after looking/slerping to the target?

Here is an example:


After this phase of rotation I want that the local rotation of the turret gets to the same level as the tank hull again.
Can anyone help me please? I tried so many experiments on my own with this stupid tank :smiley:

Here is my latest code experiment:

// The Important snippet from the Weapon.cs Script
// Transform weaponHolder = <turret set via inspector>
// The parent of the turret is the hull.

Vector3 direction = target.transform.position - transform.position;
Quaternion toRotation = Quaternion.LookRotation(direction);
Quaternion newRotation = Quaternion.Slerp(weaponHolder.transform.rotation, toRotation, Time.deltaTime * 1.5);
weaponHolder.rotation = newRotation;
weaponHolder.localEulerAngles = new Vector3(weaponHolder.localEulerAngles.x,

Take a look at my answer here:


You will need to open up the comments at the bottom of my answer and scroll down. The code is just below the link to a package that demonstrates the script.