Help with an FPS lock on system?

I’ve been reviewing tutorials and and forums posts all morning trying to find a solution to my questions, but have been less than thrilled with the results.

EDIT So basically im trying to imitate the aim lock system from metroid prime, but ill be using it for a melee based game instead

So I’m working on a first person sword fighting game, and I’m looking to make a lock on mechanic that works exactly like dark souls, where when you lock onto the enemy, your camera stays focused on the enemy so that you can move around it in a circle. I dont need the system to be able to hot change swapping targets, as the lock on system is only engaged while holding left click (its also what engages combat mode, as fighting is done solely with mouse movements.) I’d also like to specify that I need the system to lock on the enemy that is right in front of the character. I’ve been trying to modify systems that use a collision sphere to create an array of targets that you can then choose to lock onto, but the problem’s were 1. I couldn’t get the lock on to even work, and it was too specialized and would require me to copy the system multiple times for different enemy types.

Not looking for someone to just hand me the answer but if you for some reason know exactly how to do it that would be dope, otherwise just pointing me at relevant resources would really help :smiley:

So! Ive managed to get a system that checks the distance of all actors with an “enemy” tag, and then sets the closest one in a variable. What the little code at the bottom is trying to do is instead of checking for the one that is closest, I want the one that has the smallest angle to the cameras forward vector. (with all actors outside of 20 degrees to the right and left ignored) I saw a post on using find look at rotation but I dont think its going to work since looking at the enemy is 180, degrees and I also cant find a way to compare the vectors of the two enemies that are being compared.

Hey, I had worked on something similar while trying to recreate the Needler from Halo. To find the angle between your character and an enemy, you can perform a Dot Product between your character’s forward vector (Local_DirectionVector in the screenshot) & a vector from your character to the enemy. The result of the operation would give you the cosine of the angle between the two vectors. Use an Acosd node on that and you get the angle to the enemy.

Once you have that part set up, it’s just a matter of looping through all enemies to find which one has the smallest angular deviation from your character

What? Why not just use a LookAt node? (FindLookAtRotation)

As far as targeting systems go, the idea to go nearest first makes sense, but you should just use it to change target.
In other words:
If the angle is always limited and you only have 1 enemy out of the range you won’t be able to target them. This could be what you want, it could also not be it.

^ The best thing about UE4 is that there is probably a BP node or function that does what you need it to do, like Launch Character or LookAtRotation.