My dash method is as below (player2 may as well refer to self as I have 2 instances of this class where only player2 dashes).
def dash(self):
if self.dashing == True:
self.yvel = self.yvel_dash
self.dash_timer += 1
if player2.direction == 1:
player2.rect[0] += self.speed * 3
player2.rect[1] += self.yvel_dash
if player2.direction == -1:
player2.rect[0] -= self.speed * 3
player2.rect[1] += self.yvel_dash
if self.dash_timer > 10:
self.dash_timer = 0
self.dashed = True
if self.dashed == True:
self.dashing = False
if self.airborne == False:
self.dashed = False
Then after adding the tiles and world, everything works perfectly apart from the issue in title. Collision code as below in separate move method.
for tile in world.obstacle_list:
if tile[1].colliderect(self.rect[0]+loc[0],self.rect[1],self.width, self.height):
loc[0] = 0
if tile[1].colliderect(self.rect[0],self.rect[1]+loc[1],self.width, self.height):
if self.yvel < 0:
self.yvel = 0
loc[1] = tile[1].bottom - self.rect.top
elif self.yvel >= 0:
self.yvel = 0
self.airborne = False
self.falling = False
self.jump_counter = 0
loc[1] = tile[1].top - self.rect.bottom
self.dashing = False
self.dashed = True
self.rect[0] += loc[0]
self.rect[1] += loc[1]
I have tried adding more collision 'ifs' in dash function and 'if dashing' but nothing is affecting this game breaking issue and the same error occurs. Taking self.yvel_dash out of the equation doesn't alter it apart from allows the player to fall as normal when dashing as opposed to dashing straight.