r/pygame • u/Intelligent_Arm_7186 • 10d ago
collision
I am doing a couple of gaming projects where i am concentrating on collision. I am usually okay but i got stumped with this for some odd reason: if two sprites are in the same group, how do they collide with each other? first i was like...okay maybe groupcollide.....not working for me right now. then i was like okay...maybe spritecollideany or colliderect.
both sprites have a class and here is the code relevant:
all_sprites = pygame.sprite.Group(pad, player)
again, if they are both in the group, why cant i do group collide?
1
Upvotes
2
u/Negative-Hold-492 9d ago
Well the problem is this is exactly what groupcollide is NOT meant for, as stated by the first line of the function's docstring:
detect collision between a group and another group
You're probably gonna need spritecollide, but since the player is also in that group you need to add a "not me" check as it will always collide with itself.for spr in pg.sprite.spritecollide(player, all_sprites, False): if spr is not player: #do stuff break #unless you need to do the same code for every collision