Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 ?

Product Version: UE 4.15
aassasasasa.png (214.5 kB)
more ▼

asked Mar 28 '17 at 11:14 PM in Blueprint Scripting

avatar image

30 12 12 16

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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. alt text

Here is a simulation:

alt text

Enjoy :)

screenshot_5.png (233.8 kB)
more ▼

answered Mar 29 '17 at 08:25 AM

avatar image

151 4 5 8

avatar image Jakupiii Mar 31 '17 at 08:39 AM

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

avatar image DDraiman1990 Mar 31 '17 at 02:29 PM

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

avatar image Jakupiii Apr 01 '17 at 07:11 AM

Find look at rotation, sorry for late reply

avatar image DDraiman1990 Apr 01 '17 at 08:49 AM

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

avatar image Jakupiii Apr 02 '17 at 03:37 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Mar 29 '17 at 07:30 AM

avatar image

1.2k 46 29 58

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question