Skip to content Skip to sidebar Skip to footer

Collision Detection Not Working In Pygame

I am making a game at the moment and I am experiencing problems with collision detection. I am making an end of level block but it can not detect if the player is standing on it to

Solution 1:

It seems I found the problem, for some daft reason you can't use collision detection twice on the same object. I used it once so that the player could stand on the block and another time so that you could go on to the next level!

Solution 2:

The reason why it doesn't switch to the next level is that you change the position of the rect when it collides with a platform, so the player.rect gets moved out of the blocks.rect and therefore can't collide again when you call spritecollide with the endPlatform group.

A quick and dirty fix would be to check in the for blocks in platforms_hit: loops if the block is in the endPlatform group and then return True:

for blocks in platforms_hit:if blocks in endPlatform:score.add()returnTrue

And then increase the currentLevelNumber in the main function if True is returned:

change_level = player.updater(currentLevel.platforms, currentLevel.powerups, score, currentLevel.endPlatform)
if change_level:
    currentLevelNumber += 1

Post a Comment for "Collision Detection Not Working In Pygame"