collision-detection

Why is my colliderect() not working correctly?

Why is my colliderect() not working correctly? Question: Collision reacts to nothing, as if the platforms have shifted to the right. I am using it for the first time, so I would like an answer with an additional explanation… def collision(self, j): self.player_rect = pg.Rect(self.playerx, self.playery, player_w, player_h) for i in range(len(self.platfsx)): if self.player_rect.colliderect(pg.Rect(self.platfsx[i], self.platfsy[i], …

Total answers: 2

My collision detection isn't working and way to laggy

My collision detection isn't working and way to laggy Question: So here’s just the base function: def xCollision(self): for tile in tiles: if tile.colliderect(self.rect): if self.x_vel >= 1: self.rect.right = tile.left elif self.x_vel <= -1: self.rect.left = tile.right def yCollision(self): for tile in tiles: if tile.colliderect(self.rect): if self.y_vel >= 1: self.rect.bottom = tile.top elif self.y_vel …

Total answers: 1

Pygame character shaking for collisions

Pygame character shaking for collisions Question: I’m practising at pygame and I was trying to implement block id detection in my code, but after I finished it I noticed that my character is shaking. For seeing if block id detection was the problem I temporarely removed it, but nothing changed. I checked what type of …

Total answers: 1

python kivy collision detection isn't working

python kivy collision detection isn't working Question: Im trying to create a game with Python’s Kivy but my collision detection system isnt working i’ve tried many different methods on youtube but still no success it either does detect anything or just gives me error messages def collides(self, player, ball2): r1x = player.pos[0] r1y = player.pos[1] …

Total answers: 1

I'm trying to detect the collision between two moving Rects in pygame

I'm trying to detect the collision between two moving Rects in pygame Question: So I keep trying to detect two different moving rects in pygame colliding but its just constantly registering a collision. As in the console constantly print lose, but the enemy isn’t even touching the ball. The effect I want is just a …

Total answers: 1

How do I prevent the player from moving through the walls in a maze?

How do I prevent the player from moving through the walls in a maze? Question: I have a maze organized in a grid. Each cell of the grid stores the information about the walls to its right and bottom neighboring cell. The player is an object of a certain size whose bounding box is known. …

Total answers: 3

collision error self.rect.colliderect(sprite.rect)

collision error self.rect.colliderect(sprite.rect) Question: This code starts printing "collision" before it hits the sprite. This defines the "bullet" class Magic(pygame.sprite.Sprite): def __init__(self, x, y): self.x = x self.y = y self.image = pygame.image.load("Magic.png") self.rect = self.image.get_rect() pygame.sprite.Sprite.__init__(self, spritegroup) def is_collided_with(self, sprite): return self.rect.colliderect(sprite.rect) This is the collision detection code if magic.is_collided_with(enemy1): print("collision") enemy1.kill() This defines …

Total answers: 1

How do I make a pygame.draw.rect detect collision with a pygame.surface?

How do I make a pygame.draw.rect detect collision with a pygame.surface? Question: The title basically explain it all. Here’s the code for the pygame.draw.rect: stand = pygame.draw.rect(screen, green, (spike_x + 900, 400 – player_y + 476, 500, 500), border_radius=15) I want the stand to be able to collide with the player. The player is using …

Total answers: 1

How to detect collision between two objects in turtle python?

How to detect collision between two objects in turtle python? Question: So I am making a clone for chrome’s dino game in python turtle . I have done the randomisation for the cactus (which is very hackish , and yes if something is better than my aaproach , please help !)and the jumping is working.But …

Total answers: 2

Pygame collision check bug

Pygame collision check bug Question: I recently started making Atari Breakout in Pygame and I encountered a weird bug. Whenever the ball touches the left side of the paddle, it bounces off normally but when it’s on the right, it flies through the paddle. Please help, because I don’t know how to fix it. This …

Total answers: 1