1

I'm writing a platformer game utilizing pygame for a project, following allong with this tutorial and modifying the files he provided here. I have collision set up with the top of platforms, however I pop out on top when I try to move through them on the side or bottom when I want to just not move through them and fall down.

I tried using this code to make collision on all sides but I end up glitching through the platforms.

      hits = pg.sprite.spritecollide(self.player, self.platforms, False)
       if hits:
           if self.player.acc.x > 0:  # Moving right; Hit the left side of the wall
               self.player.right = hits[0].rect.left
               self.player.vel.x = 0
           if self.player.acc.x < 0:  # Moving left; Hit the right side of the wall
               self.player.left = hits[0].rect.right
               self.player.vel.x = 0
           if self.player.acc.y > 0:  # Moving down; Hit the top side of the wall
               self.player.bottom = hits[0].rect.top
               self.player.vel.y = 0
           if self.player.acc.y < 0:  # Moving up; Hit the bottom side of the wall
               self.player.top = hits[0].rect.bottom
               self.player.vel.y = 0

0 Answers0