less than -drag,
grater than drag, and
less than drag.
Probably sounds a bit confusing, it does to me, so I drew a numberline . Just assume when I say velocity, it means either X or Y.
Test Velocity Drag.png
So now I'll look at the code relative to each colour test.
1 (Blue). the first 'if' says if velocity.X < Drag AND > -Drag. Well it IS.
So in this case we set velocity back to zero.
2 (Red). Again it's going to say if velocity.X < Drag AND > -Drag. Well it is less than Drag, but not > -Drag. SO it goes to the else. Now we know that it's out of the bounds of Drag and -Drag, found through the previous if statement. So now we just define which side it's on. If velocity > Drag (so on the right of the number line). Well it's not, so it goes to the else, and velocity += Drag. And that's it, for red. That SHOULD work, right?
3 (Aqua) Again the first if statement, which defines if it's inside the bounds of Drag and -Drag. It's not so it goes to the else again. Then the second if statement : if (velocity > drag). TRUE. So it goes velocity -= Drag. DONE.
4 (Purple) The first if statement should return true, velocity = 0;
The only other positions are velocity == Drag || velocity == -Drag || velocity = 0;
All 3 of theses though would return true for the first if statement. bringing it back to zero. (Because it is actually <= Drag).
Looking at that, I don't see why it wouldn't work?
It's confusing me.
So I do what Kilorn said and put some breakpoints. If your reading it now, I haven't got around to putting them in yer .
Your're probably also wondering what actually happens instead. Well nothing.
If just moves by force. I got rid of gravity to test it, and it just moves to what ever force is, like drag isn't involved at all.
I don't see a problem in the code. I'm going to guess that the problem is in another section of the code not shown. At first I thought it was because you aren't specifically checking against negative drag, but when I ran numbers through it, I saw that it still works even with a negative velocity. So, I can't find a problem with it.
Definately step through the execution line by line in the debugger and watch the values change. Sorry I can't be more helpful.