Need help to get player to face enemy when attacking

So i am trying to make my player face enemy while attacking and to only face enemy when in range
can anyone help ?

1 Like

First, if your Player Character uses an AI Controller and a Behavior Tree, you can use “Rotate to face BB entry” node and entry should be current enemy.

If Player Character is not using Behavior Tree, simply get Enemy location and Player location, then use “Find Look At rotation” when start is player location and end is enemy location.

Then, set player’s world location to be the result of Find Look At Rotation (or only the Z value of it, to only make it rotate on the Z axis making it only “face” enemy).

All the best

EDIT FOR EXAMPLE:
The code is inside Player Character blueprint.

Here is a simulation:

Enjoy :slight_smile:

If you calculate WorldLocationOfEnemy - WorldLocationOfPlayer you get a vector that is the difference in position of the two. If you convert this vector into a rotator and set the rotation of your player to this rotator, this should do the trick.

You can also check the length of this vector to get the distance the player has to the enemy, and if it is too big, not apply the rotation.

hey thanks for the reply, i cannot get this to work it is probably very simple but do you mind sending a picture or reference ?. If not then all good

Which solution would you like me to explain? Find Look At rotation or Rotate To Face BB Entry solution?

Find look at rotation, sorry for late reply

Edited answer to show an example for better explanation :slight_smile: enjoy

Thanks heaps man i used this in anim notify and worked perfect you also helped improve my lock on system! TY :slight_smile: