Gunbound/worms like aiming system

Hi, i’m very new to all of this, and I’ve been working on it for hours now. I want to create a system similar to the gunbound/worms aim system. You use the up and down arrow keys to change your angle of fire. I’ve tried on both google and the unity3d search and I haven’t figured out a way to do it. I also tried using quaternions, but I can’t create limits for it, because I don’t want it wrapping continuously.

this is what I have currently, trying to create rotation with a limit

float maxAngle = 360;
float minAngle = 180;
void RotateShip(){
		//Grab our rotation quaternion	
		Quaternion rot = transform.rotation;
		//Grab the z euler angle
		float z = rot.eulerAngles.z;
		//Change the Z angle based on input
		z += Input.GetAxis ("Vertical") * rotSpeed * Time.deltaTime;
		//recreate the quaternion
		rot = Quaternion.Euler(0, 0, z);
		//feed the quaternion into our rotation
		transform.rotation = rot;
		if (z >= maxAngle && z <= minAngle){
			if(z < maxAngle){
				z =(maxAngle - .01f);
				rot = Quaternion.Euler (19, 0, z);
				transform.rotation = rot;
			}
			if(z < minAngle){
				z = (minAngle + .01f);
				rot = Quaternion.Euler (19, 0, z);
				transform.rotation = rot;
			}	
		}
	}

Here’s a basic example:[37149-artillaryaimingsystem.unitypackage.zip|37149]

public class Worm : MonoBehaviour {

	Transform weapon;
	public float weaponRotationSpeed = 50f;
	public float weaponMinAngle = 90f;
	public float weaponMaxAngle = 220f;

	void Start(){
		weapon =  transform.Find ("Bazooka");
	}

	void Update(){
		RotateWeapon(Input.GetAxis("Vertical"));
	}

	void RotateWeapon(float axis){

		float rot = weapon.rotation.eulerAngles.z;

		var rotationTarget = Mathf.Clamp(rot - axis, weaponMinAngle, weaponMaxAngle);
		rot = Mathf.MoveTowardsAngle(rot, rotationTarget, Time.deltaTime * weaponRotationSpeed);

		weapon.rotation = Quaternion.Euler(0f,0f,rot);

	}
}

Package enclosed with working example.

Notice that the Bazooka art itself turns around the pivot, and is offset in and of itself in order for everything to line up correctly.

Important to note, I used the MoveTowardsangle functions, which wraps correctly around whole angles (> 360f)

sry pal - somehow I deleted my former answer so I’ll continue here from your last questions:

max swipe is the allowed swipe in degrees in both axis directions from the rest pose - let’s say you have a ship model placed with z=90 and maxswipe is 45, the model will rotate from 45 to 135, therefore 90 degrees of swipe in total. To reply quicker to your second question, I upgraded my former sample adding another axis of rotation - download it down here and check it out