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 Bug

(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.


1 Answer 1


It looks like you're constantly moving the platforms to the left, as you explain, but you're only checking for collisions along the Y axis. So what happens if you fall down a pit? The platforms will continue moving to the left, the collision will register from the right side of your player, and the position will be adjusted back up to the surface of the platform. You need to implement another check that stops the player from moving horizontally in the platforms and resolving back up to the top.

If your world is moving around your character then your character's x velocity will be 0 relative to our view, but when the player collides with a platform either the world has to stop moving or the player has to move back to avoid progressing through the platforms. If the world is moving around you then you might just want to make an instant game over condition if you're colliding with the side of an obstacle rather than landing on it, or just stop the movement and let the player fall.

  • \$\begingroup\$ Thanks a lot! I have to check for the position of the player when he wasn't colliding (and not jumping), if that positions was (bottom of player) greater than the current bottom of the platform (less a fixed amount), then i stop the platforms and let him die. It isn't the best solution, in some cases the speed stills giving some problems, but it's something. Thanks again. \$\endgroup\$ Commented Jun 23, 2013 at 6:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .