Detect large actors within a radius and angle

Hi!

I’m currently working on a project where a sort of “cone trace” detection is needed in order to find which enemies are within range. The range is given by a radius and an angle, so the process that I’m following is this one:

  1. Sphere Trace by Object (from player’s center upwards and with the desired radius) in order to find the list of enemies in range.
  2. Get the direction vector (in 2D, so height is not taken into account) between the detected enemies and the player.
  3. Dot product between the direction vector and the player’s forward vector in order to find the angle cosine.
  4. Check if the cosine is higher than the desired angle cosine. If it is, the enemy is in range.

The problem is that large actors with capsules with a high radius are not being detected if the enemy’s root is outside the angle range, but the capsule is inside. Here’s an example:

200786-conetracedetection.png

I would like the enemy to be detected since the capsule is inside the desired range. The problem is that, as the enemy’s root is outside the range, using Enemy->GetActorLocation() for getting the direction vector implies that the angle check will fail.

Is there any way (not too expensive and demanding) to check if the capsule lies within range?

Thanks in advance!

Since the detected actor’s location can vertically vary, you could save that location and set its Z component to same as the trace location (Player’s center in this case). This way the angle checks should pass correctly since they are done in XY-plane.

Additionally you could use projection to that plane or you could just handle the vectors as 2D vectors if height is irrelevant anyway.

I think I have not explained it very well… I’m actually checking the angle in the XY-plane. The problem is that the enemy’s center is outside the range (in the XY-plane, height has already being ignored) but the capsule is in range and I’d like to considered that the enemy has been detected in this case.

I’m not sure if I understood this 100% correctly, but isn’t that exactly correct? You trace by channel to look for components to hit, dot product the player’s XY location with component’s XY root location and that should give you the cosine value which you can compare to your value limits?

Old question, but for anyone wondering: you can get the bounding box of the capsule and check if any of the corners are inside the cone using the same check you’d do for position. You’d just need to check the min extents and the max extents (and potentially the center). This should work for any arbitrary primitive, although the more complex it gets the more inexact it is.