reset password
Author Message
mnguyen
Posts: 9
Posted 17:21 Apr 26, 2016 |

I have my collision detection similar to how it is in the slides:

sprite.update() 
sprite.draw()
for sprite in sprite_group:
    sprite_collided = pygame.sprite.spritecollide(sprite, sprite_group, False)

for sprite in sprite_collided:
    sprite.bounce() # bounce just reverses the direction it's moving

This is making the sprites freak out in one place as they are drawn in, and all sprites spawned will collide with only the previous spawned sprite (which is the one that's freaking out).  

Any suggestions?

Last edited by mnguyen at 17:27 Apr 26, 2016.
cashpop5000
Posts: 5
Posted 01:12 Apr 27, 2016 |

I think I know the problem

You placed every sprite into one group correct?

Remember that pygame.sprite.spritecollide() will say a sprite, lets say S1, is collided with another sprite that is part of that group.

So if S1 is also part of that same group, it's actually colliding with itself then, that's why it's freaking out.

Because technically, S1 is colliding with a sprite that's in the group, even if it's itself.

So try to find a way around that.

mnguyen
Posts: 9
Posted 02:43 Apr 27, 2016 |

I think you're right.   I see it now.  Thanks