Is there a better way to implement collision in the pygame?

Asked

Viewed 134 times

0

I’m making a game, like Arkanoid. The physics of collision between objects and the screen are great.

The "colliderect(rect)" method works, but when the ball hits the batter’s sides, the ball instead of coming back, it bends into the batter, causing the coordinates of y to alternate between positive and negative until the ball exits from inside the batter.

This is the method:

def get_paddle_collision(self, paddle):
    """It makes the necessary operations according to the collision."""
    if self.rect.colliderect(paddle.rect):
        self.yspeed *= -1

I tried to implement it as a screen collision, but it didn’t work out. I’ll be grateful to anyone who can help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.