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?