title: Pygame - detect collision direction
body: <p>So i started some kinda big pygame project, everything went more or less well.</p>
  <p>But now i'm really stuck at how to detect the directions of collisions.</p>
  <p>So i got my character (2d sidescroller), and a sprite group for the obstacles which are by now all rects. Now however collision detection works fine, but is, and if it is then how, it possible to detect on which side of the obstacle rects the character rect collides with it?</p>
  <hr />
  <p>Addition in case someone <a href="https://xkcd.com/979/" rel="nofollow noreferrer">stumbles upon this question</a>: The janky solution I ended up implementing used a &quot;scaffolding&quot; of four (invisible) lines per obstacle, one for each side. Once a collision with a specific obstacle was detected I looked up the four lines around the colliding rectangle in a dict and then went to check which of these lines was currently colliding with the player sprite. It kind of worked but the whole project was a mess anyway.</p>