I’ve been trying to get this to work for two days, most posts say to put x and z to zero but that causes the barrel to keep looking at the same spot regardless of the parent object rotating on the Y. I’m exhausted and frustrated that I haven’t been able to solve it. All the commented code is everything I’ve already tried. Let me know if you need any additional information. The turret rotates correctly but the barrel keeps rotating on its own y and z when it should only move up and down (on the x axis) to look at the target.

```
public Transform target;
public Transform barrel;
public float turretSpeed;
public Vector3 positionOffset;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Move Turret
Vector3 turretVectorToTarget = target.position - (transform.position - positionOffset);
turretVectorToTarget.y = 0;
Quaternion turretVectorToQuaternion = Quaternion.LookRotation(turretVectorToTarget);
float step = turretSpeed * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation, turretVectorToQuaternion, step);
//Debug.Log("TurretVector(" + turretVectorToTarget.x + ", " + turretVectorToTarget.y + ", " + turretVectorToTarget.z + ")");
Debug.DrawRay(transform.position, turretVectorToTarget, Color.red);
//Move Barrel
//if (transform.rotation == turretVectorToQuaternion)
//{
//Vector3 test = target.transform.position - new Vector3(transform.position.x, barrel.transform.position.y, transform.position.z);
Vector3 barrelVectorToTarget = target.position - (barrel.transform.position - positionOffset);
//Vector3 barrelVectorToTargetLevel = target.position - (barrel.transform.position - positionOffset);
//barrelVectorToTargetLevel.y = 0;
//float AngleIWantToRotateBy = Vector3.Angle(barrelVectorToTargetLevel, barrelVectorToTarget);
//Debug.Log("Angle Size: " + AngleIWantToRotateBy);
//Angle between the two
//float sign = Mathf.Sign(barrelVectorToTarget.y - barrelVectorToTargetLevel.y);
//float angleBetween = Vector3.Angle(barrelVectorToTarget, barrel.transform.forward) * sign;
//barrel.transform.rotation = Quaternion.Euler(angleBetween, 0, 0);
//Setting these to zero will result in the barrel pointing directly up or down
//barrelVectorToTarget.x = 0;
//barrelVectorToTarget.z = 0;
//Get the rotation that matches the vector
Quaternion barrelVectorToQuaternion = Quaternion.LookRotation(barrelVectorToTarget);
barrel.transform.rotation = Quaternion.Euler(barrelVectorToTarget);
//barrel.localEulerAngles = new Vector3(barrel.localEulerAngles.x, 0, 0);
//barrel.transform.rotation = Quaternion.Euler(angleBetween, 0, 0);//
//barrel.transform.rotation = Quaternion.RotateTowards(barrel.transform.rotation, barrelVectorToQuaternion, step);
Debug.Log("BarrelVector(" + barrelVectorToTarget.x + ", " + barrelVectorToTarget.y + ", " + barrelVectorToTarget.z + ")");
Debug.Log("BarrelVectorQuaternion(" + barrelVectorToQuaternion.x + ", " + barrelVectorToQuaternion.y + ", " + barrelVectorToQuaternion.z + ", " + barrelVectorToQuaternion.w + ")");
Debug.DrawRay(barrel.transform.position, barrelVectorToTarget, Color.blue);
//Debug.DrawRay(barrel.transform.position, barrelVectorToTargetLevel, Color.cyan);
//}
```