Detecting enemies within X degrees of camera center?


I’m building a weapon engine blueprint, and am attempting to build a lock-on/aim assist/auto aim system akin to auto-aim in the Halo games. I’m currently blueprinting with Unreal Tournament’s editor and building off of the systems available and would like to turn the weapon engine into a mutator.

The idea is:

  • Draw a vector from 1st person camera (I’ve done this)
  • Draw a vector to all enemies
  • Detect when an enemy is within a certain angle and range
  • Activate auto-aim when this is true
  • If multiple enemies are within the angle, prioritize on the closest enemy

I want to draw a vector from the 1st person camera, and activate aim assist on enemy skeletons/collision when they fall into an angle and range relative to the 1st person camera vector.

The auto-aim will be determined on a per-weapon basis based on these variables:

This is the general idea:

Here’s my current blueprint:

I’m running into a few issues.

  • I don’t know how to draw a vector to all OTHER players EXCLUDING the 1st person player. This tutorial demonstrates the idea of what I want, but it’s AI to player, as opposed to Player to OTHER players
  • I don’t know how to determine range using vectors.
  • LineTraceByChannel doesn’t seem to want to detect when I’m pointing it at an in-game UTCharacter actor

Can anybody help?

I think I’ve made a template for that a while ago.
I will try to find it

Ben 3 days, bumping this.

For more clarity, this is the system I’m wanting to replicate.

Check out my reply in this thread. It basically explains the math behind doing a cone trace. The gist is that you can do a box trace and then reject hits that are not within the desired cone.

The Jamsh also had a good idea of just iterating over actors and testing them mathematically. In that case you may need to do some extra checks such as always check to the center of an object as well as account for the object width in the trace etc.

Okay. In no particular order, here are some answers.

To determine range with vectors, get your starting position (current player, point 1, whatever) as a world space vector. Get your end position (target player, point 2, etc.) as another world space vector. Subtract point 1 from point 2, use the magnitude node on the subtracted point 2, and use the abs node on the float output. Voila! The distance between any two points expressed as a float.

To get all players but the player this code is executing on, I would use Get All Actors of Class, and on your ForEach loop simply check that the actor is not equal to a Self reference. Alternatively, I believe there exists a function for arrays to remove a specific value from the array. You might try this function, passing a reference to self. For executing this code on something other than a Character subclass, you can get a reference to the owning player.

Bit of a semantics correction, a Vector in UE4 parlance is a location in 3D space. What you call ‘drawing a vector’ is actually a Line Trace or Debug Line between two vectors.

For LineTraceByChannel, check the channel responses on the UTCharacter BP. Also, try turning off Trace Complex, and Ignore Self on.

For your angle comparison, there is a node called GetLookAtRotation. Passing the location of your character (or camera position) to Start, and the location of an enemy (or his head) to Target, it gives you a World Space rotation for an object located at Start to point at Target. Subtracting the world space rotation of your camera or other reticle-centric component, will give you a rotator with the deviation between your current center of view and the target.

I’m sure there are a few nodes to handle the same type of operation I described (for getting the range of a vector) that work on rotators.

This should be enough to get you where you need to go; but if not, I’m always happy to answer more questions.

So I’m wanting to do something similar where you can auto aim at enemies within a certain distance from center screen.

could someone provide a screenshot of their blueprints for making a cone trace. I can’t seem to decipher how to do it from just the text. :confused:

Dot Product is what you need. Remember to normalize them all before calculation.