Help! Turret not working!

I originally posted this question in the answer hub but did not receive a reply even after I bumped it so I’m posting here instead.

I am making a turret for a tower defense game, my problem is that the turret doesn’t rotate to follow its target, I think this has something to do with the find target function as it will rotate once when spawned but not afterwards.

here are the blueprints:

90ed4ae616217b3f9bdc6c5846d9b50290318c8b.jpeg

d6126caa289ec04c84d391a91761b6739c7400fa.jpeg

72823bef63d3075cd25eea0bb37f8a0c6da80539.jpeg

This is for a university project so efficiency isn’t necessary, screenshots would be much appreciated, thank you!

Debug this stuff step by step (or rather each function).
Does find target finds targets? add there line trace make it draw lines to each target it checks for distance. When this works make it draw line only to those in range.
Then you have one line trace on event tick. Does it draw that lines?

Also functions can have input and return parameters, use them.

I am not sure how get all actors of class works. But you rotating towards last target that is in range. Not sure that but if you have more than one and your function returns different targets each frame, rotating may be just stuck.

So best if you can do line traces with debug lines for each step, you can find what works and what does not. Also for testing have one target that is in range. And 1000 is quite small do like 50k range and single actor.

Ps. there is also function that gets you all actors in sphere.

I’ve put some debug lines in, the range was too short so its now 50k so that’s fixed, the debug also reveals that the turret is finding both targets at the same time the problem might be like you said with the turret constantly switching between the two.

How do I fix this?

also how do I get the function to return a value? that would make it less confusing.

updated screenshots:

e84e32e58d6556fbfc576586a52d64e40f38d49e.jpeg

ea09f2e64e48c1f217fd9c434071555b03a56413.jpeg

run time screenshots, before:

and after, the cone is the turret, the sphere is the test enemy you can see that when the enemy moves the turret still stays in position but keeps firing.

To fix turret getting all targets, easiest would be picking first one, use that break pin in for loop node. Later, when you have it all working you can pick closest target.

For parameters, go inside function, and click on that entry node, you should get in details (right side of screen) some menu to add variables.

And you can also test that “look at rotation” where it points (turn off all displaying debug lines in other traces for testing it):
so you have that “find look at rotation”, out of its blue pin drag line and create “forward vector” node.
now it points exactly in direction that will rotate turret, but it is 1 unit long, so multiply it by 1000 then make debug trace line from location of self (turret) to location of self plus that vector.
You will see where turret should point. That is in case turret rotates incorrectly, which is quite possible.

What you do is feed into a variable the Closest Target Found and compare its distance to the Current Target Found. If it is less of a distance, you have a new Closest Target Found.

Nawrot: I’ve made some changes like this:

5dbb9f651bcb95bb776eca243231be2008db81f4.jpeg

but it’s still not working, could you explain your third point a bit better? I’m still new to UE so I’m not sure what your doing, screenshots would help.

Yggdrasil: How do I go about doing this could you show me?

Thanks for your answers by the way, they are much appreciated!

EQS can let you find the closest target, or let you find the most appropriate target if you want to go more advanced eg. target the fastest guy or strongest etc. Well worth looking into.

As for your turret itself the problem will be with it rotating to the right target, which you should be able to fix then it’s that problem out of the way.

I am not doing any code, all my answers were from what i remembe5r about blueprints.
If i have time tonight i may create some tiny “turret” project and upload to dropbox.

Thanks for the replies, I’m looking into EQS right now and it seems to be quite useful thank you!