I am working on a 2D action platformer in Pygame, though my question is a general one.
The question concerns selective collision resolution. In short, I want certain collisions to be ignored while my player sprite is rolling.
My player sprite has a roll state during which a controlled force is applied, moving the sprite forward until the roll animation finishes and the sprite's state changes to idle.
The sprite's bounding box doesn't change during this animation, since, as a rule, you don't want a sprite's bounding box to change size from frame to frame (see this answer).
My sprite is 64 pixels tall and I want him to be able to roll through 32 pixel gaps. Here's a diagram:
Currently, I do collision resolution during updates to my sprite's position. I first change his y-position according to his y-velocity, then check if there is rectangular overlap between my sprite and objects of a wall class. If there is, I place him flush with the wall. Then I update his x-position according to his x-velocity and do a similar collision check and resolution.
I was thinking I might be able to achieve my desired goal (rolling under walls) by flagging certain walls as "passable_while_rolling". The wall under which I'm rolling could be thus flagged. In my collision code, these walls would be ignored if the sprite was in the rolling state.
A problem would occur, however, if the sprite finished rolling while intersecting one of these walls. In that case, the collision code would kick in and resolve the sprite to one side of the wall in an unattractive manner.
Another option would be to just keep the sprite in the rolling state until he no longer intersects any flagged wall (similar to how you can't shift out of morph ball until you have overhead space in Metroid). I don't want to do this since I think looping the roll animation is ugly and unrealistic.
So, my questions are: What are my other options? How do other games deal with collision while rolling under walls?
I am open to drastically changing my collision resolution system.