In my pygame dungeon rpg when my player collides with a wall at the top or the bottom of its rect and I move the player in either x-direction, the player gets slingshotted off the screen. Using print debugging I've realized that when the player is colliding with the top it hits the individual hitboxes of the tiles and slingshots it to the outside of my game map because of how my collisions work.
def colliders(self): hit_list = self.collision_test(tile_rects) for tile in hit_list: if self.speed > 0: self.rect.right = tile.left print('right') elif self.speed < 0: self.rect.left = tile.right print('left') hit_list = self.collision_test(tile_rects) for tile in hit_list: if self.speed > 0: self.rect.bottom = tile.top print('bot') elif self.speed < 0: self.rect.top = tile.bottom print('top')
The tile is derived from the hitboxes of each individual tile in the above function. Speed and rect are derived from my player init function above.