I am working on a turret script and i have gotten the turret which rotates only around its Y axis to work. But i am not quite sure how to the the cannon which is a child of the turret and should only rotate around the Z axis (aim barrel up and down) to work properly.
How can i get the cannon barrel to aim aim at the target and only have it rotate in the Z axis?
Did you try the following?
Transform barrel = transform.Find ("Barrel"); barrelTransform.localRotation = Quaternion.AngleAxis (turretAngle, Vector3.right);
You may have to change Vector3.right to Vector3.up or Vector3.forward in this line of code, depending on the axis containing the longest direction (I’d recommend reexporting the object though, as it would make it more intuitive while programming).