I have 2 rects that move left and right when the rat reaches either of the sides of the rect it waits 100 secs then starts moving to the other side. My problem is I have 2 hitboxes if my player is colliding with the right one the enemy will move to the right and attack the player if its moving to the left side it will move to left side and attack the player but as you can see in the video below if I'm not colliding with the rat hitbox it stops moving. I want it to continue to move left and right and wait 100 secs.
This is how the rats are moving
if move:
if move_timer < 200:
move_timer += 1
else:
rat1.direction = "move2"
rat1.x += 1
if move2:
if move_timer2 < 200:
move_timer2 += 1
else:
rat1.direction = "move"
rat1.x -= 1
if rat1.rect.colliderect(rat11.rect):
rat1.direction = "idle"
move = True
move2 = False
move_timer2 = 0
elif rat1.rect.colliderect(rat22.rect):
rat1.direction = "id"
move = False
move2 = True
move_timer = 0
If the player collides with the right or left hitbox it should move the rat enemy to that direction the player is on sometimes when the enemy is moving towards the player and we hit the rect that moves our rat left and right it will cause glitch with the directions and it doesn't move.
elif playerman.rect.colliderect(rat1.hitbox):
rat1.x += 3
rat1.direction = "move2"
elif playerman.rect.colliderect(rat1.hitbox2):
rat1.x -= 3
rat1.direction = "move"
Here I made it so if the rat collides with the playerman hitbox then it should play the attack animation move and move2 should be false because we don't want the enemy to move left and right now it should stick to attacking the player.
if rat1.direction == "move2":
if playerman.rect.colliderect(rat1.rect):
move = False
move2 = False
rat1.direction = "at"
if rat1.direction == "move":
if playerman.rect.colliderect(rat1.rect):
move = False
move2 = False
rat1.direction = "att"
I'm not sure if I explained my problem well but what I'm trying to say is how can make my rat keep moving the direction that it kept moving if the player is not colliding with the hitbox that will move the rat towards the player enemy more and how can I stop the rect that moves my rat left and right when the enemy rat is attack the player.