About character collisions with a wall, for instance (I'll use some arbitrary values as example): if you are 10 units (e.g. pixels) away from a wall, and a single step would normally move you 20 units in that direction, the correct behavior is for your character to move 10 units and stop there. If you cancelled the action instead, you'd remain 10 units away from the wall which is not what you'd want.
One way to do this is to move the character by the full amount, then detect the collision and its depth i.e. how much the bounding boxes of the character and the wall are overlapping, and move the character back by that same amount. If you do this correctly you shouldn't be getting any "jiggle" behavior from your character, he'll just press against the wall and stop there. If he's jiggle'ing then you're probably moving him back too much (you're probably moving him back to position he was before the collision, instead of clamping it against the wall boundary).
That being said, I usually see gravity being treated as a special case. In most implementations I've seen, the character stores an onFloor
flag and gravity is only applied when that flag is false.
Edit: I guess you could expand this last concept and create additional flags such as touchingRightWall
or touchingLeftWall
, but only when the boundaries of the character and the wall match exactly. In that case you could perhaps bypass movement altogether. But if the boundaries are not matching precisely, you should let the movement take place and let the collision detection system resolve any intersections.