I'm currently developing a game in Python + Pygame and i came up with a problem with the player and the platforms. The game is a 'runner' where the player it's fixed (The 'x' position isn't variable, only the jump).
This is how i'm currently doing the collisions managment:
def collide(self, yvel, platforms):
for p in platforms:
if pygame.sprite.collide_rect(self, p):
if yvel > 0:
self.rect.bottom = p.rect.top
self.onGround = True
self.yvel = 0
if yvel < 0: self.rect.top = p.rect.bottom
'platforms' its a RenderUpdate group with the platforms (a simple sprite).
When the player is falling from a platform and collides with the next platform, not exactly on top of it but a little below, that's when the character jumps to the position shown in the code above, rather than collide and fall. I don't know how to check the left bound without a 'xvel' parameter.
(The screen shows an example, but the player only changes the y-axis coordinates, the platforms are updating their position)
I've tried supply a number to a 'xvel' parameter, and check if the character wasn't on the ground (Jumping) and the 'xvel' was greater than 0, but it isn't working at all.
Thanks in advance.