I have collision. My problem is that diagonal movement against walls isn't working. What I want to happen is that you can move left against the bottom of the wall by holding the left and up key. However when I do this it teleports me to the right side of the wall (moving left from inside the block places the left side of your character on the right side of the wall). I KNOW WHY it teleports me, I just DON'T know how to make it perfect for diagonal directional movement. I don't know how to make it so I don't get placed on the sides of the walls when moving diagonally.
I have tried many variations of wall collision and so far this is the closest I've gotten to perfect collision with implementation of all 8 directional movements. (It's pretty perfect with the 4 basic directional movements but all goes wrong when trying to go diagonal against a wall.)
def collision_check(self):
# Move the rect
self.rect.x += self.vel.x
self.rect.y += self.vel.y
self.pos = vec(self.rect.x,self.rect.y)
# If you collide with a wall, move out based on velocity
for wall in s.OBSTACLES:
if self.rect.colliderect(wall.rect):
if self.vel.y > 0: # Moving down; Hit the top side of the wall
self.rect.bottom = wall.rect.top
self.pos = vec(self.rect.x,self.rect.y)
self.vel.y = 0
if self.vel.y < 0: # Moving up; Hit the bottom side of the wall
self.rect.top = wall.rect.bottom
self.pos = vec(self.rect.x,self.rect.y)
self.vel.y = 0
if self.vel.x > 0: # Moving right; Hit the left side of the wall
self.rect.right = wall.rect.left
self.pos = vec(self.rect.x,self.rect.y)
self.vel.x = 0
if self.vel.x < 0: # Moving left; Hit the right side of the wall
self.rect.left = wall.rect.right
self.pos = vec(self.rect.x,self.rect.y)
self.vel.x = 0
I need you to be holding two of the 4 movement keys moving against the wall and another direction and not be teleported to the side you are holding.