CaydenJessen / Stay-Hidden_GAME

Game Repository for CRE311
0 stars 1 forks source link

NPC walking backwards when disengaged chase #2

Closed AndyLee-SH closed 4 days ago

AndyLee-SH commented 6 months ago

Describe the bug When Player disengage from the NPC , and NPC are returning to their original starting point, sometimes it will turn around facing the Player while walking backwards to their starting location.

To Reproduce Steps to reproduce the behavior:

  1. Player enters the NPC's detection zone.
  2. Player runs away and NPC will chase
  3. Player runs outside of NPC detection zone.
  4. NPC disengaged and walks backwards back to their starting location.

Expected behavior Expect the NPC to face the way they are walking.

Desktop (please complete the following information):

CaydenJessen commented 4 days ago

Issue Found: The Enemy Sprite would only flip when they were patrolling and not chasing the player. The Flip() method was only called when the enemy was patrolling and reached one of the points they were walking between.

Fix:

To fix this I created a method that would check whether the enemy was moving left or right by comparing their change in their x position. This change would determine whether the enemy was moving left or right. If they changed direction the enemy sprite would then flip. So instead of flipping whenever they hit a trigger, it now constantly checks which direction they are moving and flips accordingly.

image