Line trace lock on

Is there a way to get a line trace to lock onto a target. I have a turret that I control with a line trace attached, I want to be able to control the sight, but once my target lines up with the crosshairs (line trace) the way I like, I press a button and the turret then auto locks onto the target and follows it. My turret is elevated pointed towards the ground where the targets are (all targets are moving towards the turret, never away)

Also, for extra credit, can a line trace do some math and let me know the angle (in degrees) from the turret to the ground target? Since the line trace would be locked on, the angle is constantly updating the degrees smaller and smaller until the target is reached. I’ll need to use that data for certain functions later on.

Thanks! I’ll give that a try. But is there a way to do that without an event tick? Maybe a timer function? My game has too many event ticks so I’m going through all my blueprints and finding alternatives where I can.

Or start ticking when the player is within a certain distance from the turret. So when I walk up to it it starts and when I leave the area it stops

yea you could use a timer instead of tick. all that part does is update the turrets rotation so its really up to you how often you want the rotation to update. you can also set the tick interval for each blueprint class in the class settings. as for the starting and stopping thats something you could easily script as well, the way i had it setup in the above picture is that it will only update the rotation when it has a target. the same type of thing could be applied to have a condition based on distance to target or line of sight or whatever else you like.

Cool! Thanks for your help

for the lock on all you really need to do is on button presses do a single line trace and take the hit actor and assign it to a variable. then have another function that sets the rotation of your turret to the look at rotation between the turret and the target.

the setup in this picture should help get you started.