#๐Ÿ”’ pygame platformer game

9 messages ยท Page 1 of 1 (latest)

limpid sierraBOT
#

@glossy thistle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

glossy thistle
#

this code works for vertical collisions but breaks when moving on platforms horizontally. how can i fix it

sharp bloom
#

How does it break?

glossy thistle
#

when on the platform, i can stand on top of it without moving but once i move left and right it teleports me to the side of the platform

iron roost
#

I'm unfamiliar with pygame and game development in Python, in general, but I did notice these lines:

for platform_rect in platform_rects:
                    #checks for collision of any platform in the list
                    if player_rect.colliderect(platform_rect):
                        if total_movement[0] > 0:
                            self.pos[0] = platform_rect.left - self.size[0]
                            self.velocity[0] = 0
                        if total_movement[0] < 0:
                            self.pos[0] = platform_rect.right
                            self.velocity[0] = 0

Logic like on line 56 seems to just set the position to the left side of the platform whenever any collision is detected (which would be detected since you start by standing on the platform) and the speed of the player is greater than zero.

#

It seems like you need a more granular collision detection to differentiate between the player touching the sides of a platform versus the top or bottom of it.

limpid sierraBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.