1
votes

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 
2
Please provide a minimal, complete and verifiable example, otherwise it's not possible to test your code properly and you could get misleading answers. - skrx

2 Answers

0
votes

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
votes

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.