MSRevive / MasterSwordRebirth

Continuation of Master Sword Classic/Continued.
https://msrebirth.net/
Other
9 stars 7 forks source link

Arc attack system #94

Open SaintWish opened 2 years ago

SaintWish commented 2 years ago

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:

should be easy enough to calculate some ray traces in an arc, you could trace one ray for every 15 degree or smth, then accumulate up all targets hit - make it destinct and then apply damage for ex.

BerntA commented 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)

thesupersoup commented 1 year ago

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.