Beam Weapon that can be partially blocked

Hi guys,
I’m posting this here, because this is not a technical question but rather my inability to fix this with the tools I have.

Imagine this scenario:

How would I implement these kinds of attacks, if I didn’t want the player to be able to attack through walls?

If I use a simple UBoxComponent, I don’t know how to make the box stop at walls, or check if the opponent is completely (not just partially) behind a wall.
If I use LineTraces, I’d need a multitude (hundreds) of LineTraces to make the attack behave like a thick “ray”, and this probably sucks in a networked setting.

I thought about using a combination of both, first use a UBoxComponent, and then, if we hit something, use a LineTrace to see if this collision was possible, i.e. check for walls. But as you can see in the picture, if I’d use a LineTrace to check if the collision was possible, it would return false because the LineTrace would hit the edge of the wall, even though the attack SHOULD hit.

Note: This is not about projectiles, it’s about an instant ranged “attack”.

How would you approach this? This is killing my brain right now.

Thanks for your time and help guys, it’s greatly appreciated!

You could use a “sweep”. It’s like a LineTrace, but with a spere/cylinder/box instead of a point. In the above example it would collide with the wall.
A LineCast would let you shoot through narrow gaps, while a sweep would not. In exchange a sweep would hit the enemy even if your aim is a bit off.

Edit: I think I got your question wrong. Still, a few sweeps might be cheaper than a thousand raycasts, but don’t quote me on that.

Thanks for your help.
I think I settled for a Sweep. Is it possible to visualize the Box?

You can change the size of the CollisionBox that you use, the sweep will use its size. You can also get a box in one line like this:

FCollisionShape box = FCollisionShape::MakeBox(FVector(10.0f, 30.0f, 60.0f));

I think the blueprint version has an option for visualizing, but in c++ you can draw the start and end boxes like this:

DrawDebugBox(GetWorld(), start, extent, GetActorQuat(), FColor::Red, true, 3.0f);

Thanks Adam!
Is there any way to disable the automatic sorting of the OutArray that occurs during sweep?

Here it says “then overlapping hits and then first blocking hit Results are sorted”.
It’s definitely not sorted by what’s been hit first. Does a Sweep even behave like a LineTrace() in that regard?

What I’m trying to do is check if the first hit Actor from Sweep is a wall, and if it is, all other hits should be disregarded. If I place a wall behind my character and the sweep hits the character (right in front of me) and the wall (a few hundred units behind the character), the wall comes first in the output array.

You’re welcome.
I don’t know about that. How does it sort the hits?