Rotating, stopping, rotating again.

So I’m working on a mechanic with the Kinect that involves turning a wheel. The way I am doing it currently is getting the angle between the player’s two hands. (kp refers to kinect stuff, it just tells if the hand is open or closed).

void Update () {
		heading = lCursor.transform.position - rCursor.transform.position;
			if (kp.rightIsClosed) {
						currAngle = Mathf.Atan2 (heading.y, heading.x);
						transform.rotation = Quaternion.Euler (0f, 0f, (Mathf.Rad2Deg * currAngle) - (oldAngle));
				}
		
			if (kp.rightIsOpen) {
				oldAngle = transform.eulerAngles.z;
			}
				
	}

The problem I am having is that when you turn the wheel, let go, re-position your hands, and try to turn again the wheel snaps to the new hand position. What I want is that when you let go, that becomes the new ‘zero’, imagine turning a valve. Its not one continous turn but several small turns. I tried at the bottom to get the angle when you when you let go as oldAngle and then when you regrab, subtract that value from the new so you are only rotating the new amount. I’m pretty stuck so any help would be greatly appreciated.

Here is a quick script for how I might approach the problem. I’m not sure of frame of reference, but I think your heading vector is backwards. That is Vector3.right is the 0.0 angle for Atan2, so looking towards positive ‘z’ , you want to subtract the left from the right. But maybe the names don’t mean what I think.

private bool grabbed = false;
private float startAngle = 0.0;
private Quaternion startRot;

void Update () {
    if (kp.rightIsClosed) {
        Vector3 heading = rCursor.transform.position - lCursor.transform.position;
        float currAngle = Mathf.Atan2(heading.y, heading.x) * Mathf.Rad2Deg;
        if (!grabbed) {
             startAngle = currAngle;
             startRot = transform.roation;
            grabbed = true;
        }
        else {
            currAngle -= startAngle;
            transform.rotation = Quaternion.AngleAxis(currAngle, Vector3.forward) * startRot;
        }
    }  
    else {
        grabbed = false;
    }      
}

transform.rotation = Quaternion.Euler (0f, 0f, (Mathf.Rad2Deg * currAngle) - (oldAngle));

Setting the rotation like this is not adding to the rotation. You’re creating a brand new rotation that is rotating x, y, and z degrees from origin.

If your object was at 30 degrees and they let go, then try to turn another 30 degrees, your object will get set to 0 degrees rotated from origin. You need to add your previous angle to your rotation.