I’m making a game that uses the x-axis of the accelerometer. Tilt it left, the little guy goes left, and vice versa.
Right now, if I tilt left, he’ll move left and the x value goes negative. When I start moving right (from the left position) he’ll still go left being the x value is still negative and he’ll only start going right after the value returns to 0 then increases.
My question is, how do I detect that the the phone is turning right, before it’s actually in the quadrant(?). Like, how do I make him move right, even though the value is still negative, but is increasing towards 0?
You don’t want the x value, you want the x delta
(after every change in x, compare it to it’s previous value, that’s your direction. then save that value of x as your new comparator)
(not objc)
x is the current X position, the return value from the functions gives you your current direction. (Please check my work – I believe it’s correct but wouldn’t use it for missle guidance)