Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm doing a game where one component is that you turn a knob. I'm having trouble getting good "knob behavior".

I know the current touch/mouse X,Y location, and I keep track of the previous X,Y location, so I can determine if I'm going left or right and/or up or down.

It works, but it's crude. I suspect I have to take an average of any given direction over a period of time (say, last quarter second) to eliminate jitter because people don't move uniformly in the same movement every moment.

I can't really use touchdown/release because you should be able to put the touch down, then move left/right up/down continuously without release, and the knob would turn, just as if you had a free-spinning audio control or video shuttle (say).

Any thoughts in this direction on how to even it out?

share|improve this question
    
Take a look at this: soundstep.com/blog/2011/04/08/… The function :updatePosition. It uses Atan2. –  Sidar Feb 1 '13 at 17:13
    
I'd definitely recommend using the angles to find a rotation for the knob which like Sidar said best done with Atan2. You will still need to remove some of the shakyness of the control (which can probably done by only allowing the turn after a certain deltaAngle value is reached) –  Benjamin Danger Johnson Feb 1 '13 at 17:55
    
Try to be a bit more generic in your questions. Emulating a door knob is not a common activity. Rotation based on touch is more common and has been asked before: gamedev.stackexchange.com/questions/29799/… –  Byte56 Feb 1 '13 at 18:51
    
@Byte56 the OP doesn't mention "door" in a question. When I hear "knob" I'm thinking like a control knob on a switch board and he wants to convert mouse movement to a hand twist gesture. –  Tetrad Feb 1 '13 at 19:44
    
@Tetrad True enough. But OP doesn't mention mouse movement either ;). It's using touch to cause rotation, no? If it's rotating a sprite or controlling a knob, it's taking a change in position and converting it to a rotation value. Seems like they're the same to me shrug. –  Byte56 Feb 1 '13 at 19:48
show 4 more comments

1 Answer

Instead of just using deltas, have you considered just linearly mapping the distance from the start of the touch to some rotation value?

So let's say you start at position (x,y) and your knob is currently rotated to point to angle theta. As long as your finger is held down, you update the current angle of the knob. At position (x+z,y+w) you figure that you moved z+w distance (using manhattan distance so you can go negative), which you then multiply by some scalar value r to give you how much you should rotate the knob. Say 1 radian of rotation equals 100 pixels movement (so r = 100 in this case). So current rotation = theta + ((w+z) / r )

I probably would do something like that first before going for angle checks and things like that since, as a user, if I want a knob to increase I'd probably just want to drag it to the right instead of having to drag around in a circle. If you went with the angle, the user might get into a situation where dragging "more" doesn't increase the knob as expected, assuming your knob rotates more than 180 degrees.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.