Open SaintWish opened 2 years ago
a simple formula could be
ray trace this for every X degree until 180 degrees (probably better to use radians):
(crosshair pos / aim pos) + (vecForward * sin(degrees) + vecRight * cos(degrees)) * range
(start pos is always crosshair or aim pos)
I implemented a similar system for NPC field of view in C#: https://github.com/thesupersoup/Hubris/blob/master/Core/FOV/FOV.cs We could allow for spells/weapons/etc. to use any of 60, 90, 120, and 180 degree arcs, because the values for those are easily prebaked. Then you just get the player's forward vector and can determine if it's in the arc fairly quickly. I think the range test would be separate for performance's sake, you could sidestep the potentially more expensive (but also single-frame) number crunching of the arc determination.
e.g.
if (isInRange)
{
arcTest();
}
Note that my implementation of FOV is deliberately flattened for performance and simplicity. If they're "in range" then it doesn't make a huge difference anyways.
Give scripters a way to create weapons or an attack on a weapon to do an "arc" attack to hit multiple enemies in a range.
As suggested by BerntA: