x

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"

Lock on system not working on moving target

I have made a lock on system, but when i move the target in game by bumping into it (it is simulating physics) my character keeps looking at the begin position, even if the actor is destroyed or completely somewhere else. This is weird because i'm using the FindLookAtRotation node in a function connected to an Event Tick so it should update the target location right?

Also, when i have two enemies in the scene, i can only lock on one and with the other one the player turns to the enemy once but doesn't keep looking at it.

I have absolutely no idea what i'm doing wrong. It feels like i have tried everything.

Any help would be appreciated!

Pictures: alt text alt text

Video example:

https://drive.google.com/open?id=1W4ry4Yi-Dh35GkgjxOewoqRNUThyVOGW

Product Version: UE 4.22
Tags:
function.jpg (280.9 kB)
function.jpg (280.9 kB)
lock-on.jpg (75.0 kB)
more ▼

asked May 01 '19 at 10:17 AM in Blueprint Scripting

avatar image

MakkerFelix
77 6 6 13

avatar image Nebula Games Inc May 01 '19 at 01:54 PM

Just as an aside if you wanted a more optimized "nearest enemy" function you could use this node that will do all the work for you and return a sorted array based on distance for you to choose from.

https://youtu.be/cWesVY0zF0U

It looks like this:

alt text

distance-sort.jpg (87.7 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

[...]but when i move the target in game by bumping into it (it is simulating physics) my character keeps looking at the begin position, even if the actor is destroyed or completely somewhere else.

This is because the actor does not really move, the simulation is only moving the mesh. Make the mesh the root of the actor. Or use the mesh location with Find Look At.

more ▼

answered May 01 '19 at 10:48 AM

avatar image

Everynone
15.2k 77 25 62

avatar image MakkerFelix May 01 '19 at 11:11 AM

Thank you! That works. The only problem now is that i can only lock on to one enemy in a scene for some reason.

avatar image Everynone May 01 '19 at 11:28 AM

The first thing that looks jarring is the loop itself. You're not really finding the nearest enemy, you're finding several enemies that are close enough and look at the last one on that list. Also, you set every enemy as the closest one and try to look at the every enemy again.

Wouldn't it make more sense to find the closest enemy in the loop and only then rotate once? It would look like this or thereabout:

alt text

The variables are local so you do not need to Clear anything when calling.

Completely untested but should work fine. Fingers crossed! Do tell if something does not add up.

edit: Not sure how the lock mechanics is supposed to work but perhaps the boolean Lock check should be done before even running this rather costly function - no reason to find the closest enemy if you're not Locked anyway - or am I misinterpreting how it's supposed to work? Hard to tell what the goal is. :)

edit2: Oh, I think you want to be Locked to the closest enemy providing it's in the desired range, yesh?

capture.png (228.3 kB)
avatar image MakkerFelix May 01 '19 at 12:31 PM

After a while of puzzling i figured it out.

For anyone who wants to have a system like this: alt text alt text

function.jpg (249.3 kB)
eventgraph.jpg (74.2 kB)
(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