I have a turret that is a child of a tank.
When the tank is on a flat surface and the turret aims at the target all goes well because the tank is on the horizon line, but as soon as it goes uphill or downhill or any other X or Z axis rotation its noticeable that the turret that is attached to it does not follow.
This turret is already rotating along its own Y axis to aim at the target, and thats working fine, but the problem is that the rotation along its X and Z rotations are always “zero”
This is because im using rotation instead of localRotation:
//Turret Head
RotationHeadHelper = Quaternion.LookRotation(TargetEnemy.transform.Find("TargetAim").position - TurretHead.transform.position, Vector3.up);
float rotationY = RotationHeadHelper.eulerAngles.y;
float newYAngle = Mathf.MoveTowardsAngle(TurretCannon.transform.rotation.eulerAngles.y, rotationY, rotationSpeed * 10.0f * Time.deltaTime);
TurretHead.transform.rotation = Quaternion.AngleAxis(newYAngle,Vector3.up);
I cant figure out a way to make the turret to have the same X and Z rotation of its parent, the tank.
You could say that, If you visualize (like inside the editor) the XYZ gizmo on the turret, then pick the arrow point up, Y green arrow… the turret is always the same as the global Vector3.up, but the tank when going up or down on the terrain is obviously not…
I think the picture below will help make more sense
So… I know I have a few options but I do not know how to do it.
I know I can make the UP orientation of the turret to be the same as the tank(who is the parent)
I know also that I could convert the lookRotation from global to local somehow and then apply only the Y axis rotation
…
Well there must be loads of ways but I lost enough hair trying to figure this out, Im no good with 3D math, just the basics…
Any help much appreciated:p
