1

It detects collision most of times, but sometimes it doesn't. Here is collision checker:

def collide_check(this, object_1):
    bullet_rect = this.image.get_rect().move(this.bullet_x, this.bullet_y)
    object_1_rect = object_1.image.get_rect().move(object_1.ice_x, object_1.ice_y)
    if bullet_rect.colliderect(object_1_rect):
        #consequences of collision 
S4V4GE
  • 21
  • 3
  • Please provide a [minimal, complete and verifiable example](https://stackoverflow.com/help/mcve), otherwise it's not possible to test your code properly and you could get misleading answers. – skrx Jun 08 '18 at 21:14
  • Possible duplicate of [Fast projectiles don't always hit](https://stackoverflow.com/questions/18478352/fast-projectiles-dont-always-hit) – TemporalWolf Jun 08 '18 at 21:18

2 Answers2

0

Looks like your typical 'Bullet through paper'-problem.

Since .move() doesn't sub-step you are simply not overlapping the other rect, and therefor do not fulfil the colliderect condition.

Simply put: You 'erase' the original rect, and draw it anew in the new position. Same for the other rect. They do not overlap, because the movement was too great, therefore no collision is detected.

-1

If you're calling collide_check() multiple times on the same object, I may have found the reason for your problem.

For unknown reasons, .colliderect() won't detect collisions if it's being called on an object that has already had collisions detected upon it.

For more information, see this similar question.

Adi219
  • 4,712
  • 2
  • 20
  • 43
  • 1
    *"For unknown reasons, .colliderect() won't detect collisions if it's being called on an object that has already had collisions detected upon it."* That is incorrect. You can call `pygame.Rect.colliderect` as often as you want and it will detect the collisions correctly. – skrx Jun 08 '18 at 21:13