Python Forum
Problem with collision detection...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with collision detection...
#1
Hello,

This is a piece of my current project. It is in my "class Player()". It's pretty standard, but not working. The "walls" group is defined globally at the top, and when tested has sprites in it, yet my player sprite just moves right through walls and I don't get any errors.



    def move(self, dx=0, dy=0):
        
        if not self.collide_with_walls(dx, dy):
            self.rect.x += dx * tile_size
            self.rect.y += dy * tile_size
        
    
    def collide_with_walls(self, dx=0, dy=0):
        
        for wall in walls:
            if wall.rect.x==self.rect.x + dx and wall.rect.y == self.rect.y + dy:
                
                return True
        return False
Reply


Messages In This Thread
Problem with collision detection... - by michael1789 - Nov-12-2019, 01:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [PyGame] Problem with collision of player and enemy Nekotrooper 1 894 Dec-08-2023, 03:29 PM
Last Post: deanhystad
  can't get collision detection to work in platform game chairmanme0wme0w 10 4,116 Aug-19-2022, 03:51 PM
Last Post: deanhystad
  [PyGame] Collision in not happening onizuka 3 3,539 Sep-07-2020, 11:30 AM
Last Post: metulburr
  [PyGame] No collision detection onizuka 6 3,824 Aug-18-2020, 01:29 PM
Last Post: onizuka
  Arcade Collision Problem randor 0 2,751 Oct-28-2019, 11:17 PM
Last Post: randor
  Multiple wall collision in pacman rustyjoe 4 4,251 Aug-11-2019, 08:08 AM
Last Post: rustyjoe
  drawing, moving, and collision problems (pygame) SheeppOSU 26 15,258 Apr-22-2019, 03:09 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020