79409952

Date: 2025-02-03 20:37:18
Score: 2
Natty:
Report link

Since your enemies are following the player, you can find which direction they are going by substracting Player's position from Enemy's position. Then you can decide which animation to play just like you did on your if-else statements.

Vector2 facingDirection = new Vector2(player.transform.position.x - enemy.transform.position.x,
     player.transform.position.z - enemy.transform.position.z);

if(facingDirection.x > 0 && facingDirection.y > 0) {
   ...
}
if else(facingDirection.x < 0 && facingDirection.y) {
   ...
}
...

We used transform.x and transform.z of player and enemy because your game is in 3d world and we dont want to go up (y axis is up).

If you didnt understood why we substracted positions I recommend you this video

https://www.youtube.com/watch?v=sYf4bSj9j2w

Reasons:
  • Blacklisted phrase (1): youtube.com
  • Blacklisted phrase (1): this video
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: BringSalavat