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.
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.