def update(self, player_rect):
different_x = player_rect.x - self.rect.x
different_y = player_rect.y - self.rect.y
if abs(different_x) > abs(different_y):
if different_x > 0:
if not self.check_collision(-self.speed, 0):
self.rect.x += self.speed
self.animation(kind="right")
else:
if not self.check_collision(self.speed, 0):
self.rect.x -= self.speed
self.animation(kind="left")
else:
if different_y > 0:
if not self.check_collision(0, -self.speed):
self.rect.y += self.speed
else:
if not self.check_collision(0, self.speed):
self.rect.y -= self.speed
When the main character just stands still, he runs at normal speed, and when I move, he, so to speak, floats or flies after me, although my speed is greater, and I should be ahead. Perhaps this is due to the dynamic camera, if you need an addition, I’ll add it
New contributor
Dima Yatsenko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.