How to change another actors flip book relative to the players location?

I am working on an FPS RPG game. Instead of meshes, I am using 2d flip books for all actor blueprints. I can make the flipbook face me, but I want it to change if the actor is not facing me, For instance, if the actor walks towards me and then turns around I want it to display a different flipbook.

If you’re using standard movement inputs you can use

211795-ue-answerpic34a.png

to get the last direction you told the character to go, and compare that with world location of the player and item.

Or you can store current direction of your character, and have the item access that directly

  • For instance, if you know the player look direction X, and the X difference between the item and character, call it A (Item World Location - Player World Location)
  • Then the Player is looking at the item if the sign of X and A are the same.
  • IE. Player is at 0, Item is at 1, and the player is looking to the right.
  • Item Location - Player Location = 1 - 0 = +1
  • If the player is looking to the left, the sign of their direction vector is -1, and to the right would be +1
  • So in this case, if the player is looking to the right, they are looking at the item, which is true.

Nice Ben! this is a bit confusing though. can you give an example?

Understandably.

  • If your item has a reference to the player, then it knows where it is… and can know which way it is looking.
  • You can then use math on the horizontal axis to compare the direction the Player is looking, and compare that with the direction the Item is from the Player.
  • Get Last Movement Input Vector is a function available to pawns if you are using Movement Input. It returns a vector(XYZ) direction the pawn was last told to travel towards.
  • You also know the vector location of the player pawn, and the item. If you subtract Player Location from the Item Location you can then break that vector to get the distance and direction in XYZ, direction is represented by -/+.
  • If the player is looking to the left, then the movement input vector on that axis will be negative.
  • If the item is to the left of the player, then result of the subtraction on that axis will be negative.
  • So if the player is looking left, and the item is to the left, then you know the player is looking at the item. The total opposite is true, if both values are positive, then you know the player is looking at the item.
  • You can get the -/+ value by using the Sign function on a float value, which will return -1 or +1.

Wow! I’m completely lost lol. Like I do get what you are saying (kind of) but I have no idea how to put that together in blueprints.