How to make 2D sprites of an NPC change depending on what dirrection I'm looking at it?

So, I want to make an NPC with 2D sprites that can patrol around the 3D area, chase the player etc. I mostly figured out those things. I made a walking animation on Blender. I rendered the same animation four times, one for every direction, and imported them in UE4, sprite flipbook and all that. Now, my question is, how do I make those sprites change depending on which direction I’m looking at that NPC? If I’m in front of it, I want the sprite that is looking directly at me. But if I start passing it and end up looking at it sideways, I want the sprite to change, so that I see the sprite that’s sideways. You could say I want the same effect that “First prize” character from Baldi’s Basics has. Could someone lend me a hand?

Sorry to resurrect an old topic, but this is also very interesting to me. It seems (to me at least) you somehow need to find a vector from the NPC pointing towards your character. Then compare that vector to the NPC’s z-axis. If its between

  • 315 and 45 degrees, display the forward facing sprite
  • 45 and 135 degrees, display sideward facing sprite
  • 135 and 225 degrees, display backward facing sprite
  • 225 and 315, display sideward facing sprite

But I have NO idea how to do this, there’s even a chance Im barking up the wrong tree here completely. Maybe someone with more experience knows?