Detect if player is inside Area of Effect?

I have this customizable Area of Effect indicator using a single material as a decal, attached to an actor. What I’m struggling with is finding a way to detect whether or not the player is standing inside an AoE.

Referring to the image, I can produce “complex” shapes (rainbows/cones/donuts/etc). I absolutely do not want to create object meshes for each possible shape. I don’t need to tell you just how many 3d models that would be based on the sliders in the image.

Originally I’ve tried using sphere/capsule colliders for the circles, but introducing a “cone” has made this infinitely more complex for me. I also tried using the Procedural Mesh component, but wasn’t quite sure of my ability to use it.

Again, I really want to stay away from creating 3d meshes for each possible AoE I can make. Other than that, I am looking for any help I can possibly get.

Have a look at how dot product works:

Seems like the way to do here.

(rainbows/cones/donuts/etc)

  • cone is just a dot
  • rainbow would be dot and min | max range
  • donut is checking whether the target is in min | max range

What I’m struggling with is finding a way to detect whether or not the player is standing inside an AoE.

If you do not want to create uniquely shaped colliders, you’ll need to math it out. Sphere overlap nearby targets and then iterate to check whether they meet other criteria like the min range (donut hole) or dot product (cone).

1 Like

get decal actor object radius or object bounds and calculate if other actor is inside.
it doesnt have to be the exact shape of the vfx…

The question is how to calculate. Your answer is to calculate. :medal_sports:

The shape is not a box, it’s not even a full circle, mate…

Assuming this is specifically a ‘round’ AoE…

Create a scene component.
Rotate the scene component locally by whatever the rotation axis needs to start at (say -60 degrees)
Add and child a box collider to the scene component, with a width of 1-unit and a length of the radius of your AoE
Then, rotate the scene component locally by whatever you need adding any ‘beginOverlap’ actors to an array
After rotation finishes apply you effect to the array of actors

I think sweep doesn’t work with rotation.

I think you’re right, should still work fine if you move it incrementally by, say, one degree or so.

What’s up with those answers? OP said he cannot use colliders as the shape changes… Also, Sweep and Rotations is a no, no.

How would you do it for a 63deg arc and then for a 170deg attack with the exclusion zone in the middle that is run-time adjustable?

Pseudoscript:

Punch in the directional vectors, the angle of the attack and range. With this you get, cone, rainbow, full donut and a pizza slice.

2 Likes

OP said "Originally I’ve tried using sphere/capsule colliders for the circles, but introducing a “cone” has made this infinitely more complex for me. "

I offered a solution for the semi-circular ones in their post, and it can be adapted for use with the other shapes. For example, you can do the cone by using two box colliders, and get the base set of relevant actors with one, and remove those from outside it by a certain radius by having a second longer collider rotate at a wider angle.

The 'rainbow shape can be created with a box or sphere collider, offset from the scene component, and then rotate the scene component around the x

I mean, I’m just offering one solution, which can be used for OP’s purposes. It might not be the ‘best’ way, but it was the first solution that came to mind, and I figured a ‘not perfect’ answer which at least does what they’re asking for is better than no answer.

2 Likes

I’m just being defensive - I have a soft spot for dots. :wink:

Technically, you can use 4 cones and scale them to get most of the shapes about right. Here’s an example with a single cone:

1 Like

I’ve never used physical material masks but I believe you could make a physical material mask with two physical materials, one would be for the hit area and the other for the no-hit area, and then you could do a line trace from the character to get the physical material and the distance and see if character is within hit range.
(I’m a newbie and have no idea if that would work)

Ha, alright. Honestly, reading up on dot I think it’s likely the more efficient method, from a technical standpoint. I mainly went for the collider option since OP said they had tried, and I was able to visualize it mentally. I’m more of a visual person these days, so I suppose that’s where I was coming from. I mainly was looking at it like using two colliders to create essentially how the Spot Light has “Inner Cone” and “Outer Cone” but as a way of shaving off the actors outside the inner one.

Wish those worked, like at all. You can set them up and… then what? Never got it to work. :frowning: If you have an example of it working, I’ll gladly take it.

This works great! Thank you so much. I apologize for the late reply, I had posted the thread before going to sleep, and I didn’t have the time to test your script.

My last question for now is, how do I convert a range of integers (10-0) to a float scale of -1 to 1? Is there a dot product equivalent for integers/floats instead of vectors?

EDIT: Scratch that last part. I figured it out! (x - 5 ) / -5 is the formula I’m after!

1 Like

Hi, me again.

I’ve been playing around with this method and I’ve noticed a small issue. If the player is standing too close to the center, the DOT product registers as being less than the angle of the cone, even though it’s well within the range.

Any idea why this happens?

Sounds a bit as if the directions were not calculated correctly. Perhaps there’s an Z discrepancy? Hard to tell without seeing it. Best to discard Z; it could look like this:

Drawing Xs on targets that would get hit with the math.

2 Likes

I always forget about the Z. That fixed the problem of objects being too close not getting detected. The final issue I think I have now is that objects outside of the cone are being picked up as well.


The debug cone and material cone are both 90 degrees. The boolean check should be 90 degrees as well, assuming 0.5 is translated to 90 degrees and my math is correct.