I'm trying to simulate unscrewing a nut from a bolt. To me, this means tracking the y-rotation and moving the nut on the y-axis depending on the direction the nut is rotating. The problem is that euler angles loop between 0 and 360 and quaternions between -1 and 1. This causes my nut to only be able to move up and down within a single rotation.
I've considered trying to catch the jumps (ie detecting rotation.y jumped from 359 to 1, rotating clockwise) and compensate for them, but there were a lot of edge cases this wasn't good. What's the best way for me to go about this? Any help appreciated, thanks.
I knew it must be more complex. In the past I always used to handle translation and rotation seperately - but not using Unity I'm afraid. All I can say is because this is a nut + bolt, the rotation of the nut is 1:1 linked to the offset along the bolts shaft. You need to standardize your math on the amount of offset. This means that the input rotation can be calculated back to shaft offset (ratio of twist to offset) and then worked forward to get final rotation of the nut (you can't go whacky doing this because you're working out angle of rotation afresh each time).
I moved this from a comment, because I didn't think that I was clear. Basically it doesn't matter if your rotation is at 20 degrees, and you want to apply -50 degrees. You would basically apply 50 degrees worth of offset either up or down the shaft and then work forward to get the angle of the nut - so you'd still end up with a 330 degree rotation, but that rotation wouldn't act to clip the position on the shaft.
Following this model, your shaft could be 40mm long or 1m long and you'd be able to wind the nut all the way along - you'd just need the stopping condition at the head, and the event to say that it's undone at the end.