Weird angle values from GUIUtility.RotateAroundPivot...

I have finally finished a working script to rotate a steering wheel in my 3d game. Next step is getting it to actually move my car.
Although this is impossible at the moment because of the angle values which I am using are very weird… Here are a few screenshots with console output of the angle variable…[27296-screen+shot+2014-06-05+at+6.15.19+am.png|27296]

Here is my steering wheel script

@script ExecuteInEditMode()

	public var texture : Texture2D = null;

	public static var wheelRotation : float = 10f;
	
	private var angle : float = 0;
	public var turnVar: float = 0;
	public var sizeFloat : float = 0f;
	public var size : Vector2 = new Vector2(0, 0);
	var xPosF : float = 0f;
	var yPosF : float = 0f;
	var btp: Vector2;
	private var pos : Vector2 = new Vector2(0, 0);
	private var rect: Rect;
	private var pivot : Vector2;
	private var rotating : boolean = false;
	private var initialMouseAngle : float;
	
	function Start() {
		UpdateSettings();
	}
	
	function Update() {
		turnVar = angle;
	}
	
	function UpdateSettings() {
		sizeFloat = Screen.height / 2.3;
		size = new Vector2(sizeFloat,sizeFloat);
		xPosF = Screen.width/7.5;
		yPosF = Screen.height/1.25;
		pos = new Vector2(transform.localPosition.x + xPosF, transform.localPosition.y + yPosF);
		rect = new Rect(pos.x - size.x * 0.5f, pos.y - size.y * 0.5f, size.x, size.y);
		//Debug.Log ("Rect="+rect);
		pivot = new Vector2(rect.xMin + rect.width * 0.5f, rect.yMin + rect.height * 0.5f);
	}
	
	function OnGUI() {
	
	if(Input.touchCount > 0 ) {
 
		for(var i : int = 0; i < Input.touchCount; i++) {
 
			var touch : Touch = Input.GetTouch(i);
						
			if(touch.position.x < Screen.width/2.5) {
				btp = touch.position;
			}
			
		if (Application.isEditor) { UpdateSettings(); }
		
		btp.y = Screen.height - btp.y;
		
		if (touch.phase == TouchPhase.Began && rect.Contains(btp)) {
			var v2T : Vector2 = (btp - pivot);
			initialMouseAngle = Mathf.Atan2(v2T.y, v2T.x) - angle * Mathf.Deg2Rad;
			rotating = true;
		}
		else if (touch.phase == TouchPhase.Moved && rect.Contains(btp)  && rotating) {
			v2T = (btp - pivot);
			angle = (Mathf.Atan2 (v2T.y, v2T.x) - initialMouseAngle)  * Mathf.Rad2Deg;
		}
		if (touch.phase == TouchPhase.Ended && rect.Contains(btp)) {
			rotating = false;
		}
		}
	}

		var matrixBackup : Matrix4x4 = GUI.matrix;
		
		GUIUtility.RotateAroundPivot(angle, pivot);
				
		GUI.DrawTexture(rect, texture);
		GUI.matrix = matrixBackup;
}

Here is the code I am currently using to turn the vehicle

FrontLeftWheel.steerAngle = (sWheel.turnVar)/Mathf.Clamp(rigidbody.velocity.magnitude/15,1,20);
FrontRightWheel.steerAngle = (sWheel.turnVar)/Mathf.Clamp(rigidbody.velocity.magnitude/15,1,20);

1 Answer

1

try Math.Clamp(-5, 5)