Pygame collision handling
0
I made a 2D platformer game with pygame. I am struggling to figure out how to determine the direction an object is moving in. For example: say the player is coming from above since his y velocity is greater than zero, then the problems are that his gravitation is acting on him constantly; this means that if he comes from the left side, his y velocity is greater than zero (so this if statement will get triggered even though I want the left-side-if statement to get triggered). The source code for this is the following: ` if self.hits: for platform in self.hits: if self.player.vel.y > 0: self.player.rect.y = platform.rect.top self.player.vel.y = 0 if self.player.vel.y < 0: self.player.rect.top = platform.rect.bottom self.player.vel.y ...