Hi, im new to unity and i need help.
I want to rotate a turret of a hetzer (just google it, its a tank)
The turret is fixed at the front of the tank and can only move there (just google hetzer to see what i mean).
when the tank is not mooving, its working fine, but when i rotate the tank at the same time as i rotate the turret, then the turret rotates out the the boundaries, here is the script:
public var gunPrefab:Transform;
private var gun:Transform;
function Start () {
gun = Instantiate(gunPrefab,transform.position,transform.rotation);
gun.parent = transform;
}
function Update () {
var temp : Vector3;
temp.x = Input.GetAxis("Mouse Y") * (-1) ;
temp.y = Input.GetAxis("Mouse X") ;
temp.z = transform.rotation.z;
if((temp.x > 0 && gun.rotation.x > 0.1) || (temp.x < 0 && gun.rotation.x < (-0.1)))
{
temp.x = 0;
}
if((temp.y > 0 && gun.rotation.y > 0.15) || (temp.y < 0 && gun.rotation.y < (-0.15)))
{
temp.y = 0;
}
gun.transform.Rotate(temp);
}