pygame - setting up collide whether right side or left side of collision box. Directional.

Опубликовано: 02 Июнь 2026
на канале: George Thornburg
322
3

pygame collide sides

I solved this by creating multiple collide boxes. This should help a lot of people.

if tanner.axe.colliderect(oak.red) and tanner.playerHitBox.colliderect(oak.leftHit) and keys_pressed[pygame.K_SPACE]:
Number_of_Hits_Left += 1
print(Number_of_Hits_Left)

if tanner.axe.colliderect(oak.red) and tanner.playerHitBox.colliderect(oak.rightHit) and keys_pressed[pygame.K_SPACE]:
Number_of_Hits_Right += 1
print(Number_of_Hits_Right)

So I have a total of 5 hit boxes to accomplish said mission. And really all you would have to do is create your main hit box, then create 2 side boxes on the left and right side of main hit box, so that they barely overlap. So let's say you shoot a bullet your code would be something like above. "When bullet collides with side box AND when bullet collides with main box, do something."