touch.positionDelta Rotation

Im rotating an object on the x axis only, im using touch.positionDelta to track the change in finger movement and this rotates the object, the only problem im having is that when the touch goes past x=0 into minus figures the object starts rotating back on itself…

Can someone point me in the right direction?

function Update() {
	

	for (var i : int = 0; i < iPhoneInput.touchCount; i++)
	{
	var touch : iPhoneTouch = iPhoneInput.GetTouch(i);
		//Debug.Log (touch.phase);
			//Debug.Log (touch.positionDelta);
			var moveDirection = -1;
			var x = (touch.positionDelta.x);
			
			
	transform.Rotate(x, 0, 0);

bump (same question)

anyone?

Let me understand:

Are you trying to rotate the object in the same direction regardless of the direction of finger movement along the x-axis?

Im trying to make it so that when the user moves their finger and drags their finger on the object it rotates the object in 2 dimensions in the direction of the drag… also the rotation can only take place when the finger is on the object…

thanks

Ah, so you’re making a knob. Well, you have to pay attention to touch.positionDelta.y as well if you wanted to do it on the deltas, since you are using x and y screen coordinates to rotate around the x axis. In other words, your finger isn’t moving in a straight line.

But, a different approach would be to use the actual positions and compare x and y to the point of rotation on the screen. Taking the deltas you would then compute the change in angle since you have a triangle based on:

Current x and y (point 1)
Old x and y, which is current minus deltas (point 2)
Center of rotation (point 3)

The immediate problem is that this is not a right triangle. So, you need to reset P1 to be the intersection of p2 at a right angle with P1P3. That will give you a right angle at p1. Now the angle at P3 is simply the ASIN of the length of P1P2 divided by the length of P1P3. That is in radians, so you convert it to degrees for your final rotation.

Maybe someone else has an easier method such as attaching a spring joint to the knob at the correct position on the object and simply moving another gameobject directly with the finger.

Thanks for your response, but it does seem rather complicated to implement, does anyone else have any suggestions?