smilz0 / Left4Bots

Improvements for the L4D2 survivor bots
https://steamcommunity.com/sharedfiles/filedetails/?id=3022416274
34 stars 4 forks source link

[Improvement] Manual Attack Adjustments #76

Closed MutinCholer closed 7 months ago

MutinCholer commented 8 months ago

Currently, the method for aiming at targets relies on using m_hasVisibleThreats in the Left4Bots.AIFuncs.BotManualAttack function to determine whether to call the Left4Bots.FindBotNearestEnemy function. Once a target is within a SurvivorBot's FOV, it attempts to call the Left4Utils.CanTraceTo function for each entity to determine whether to consider it a new target.

Two problems arise with your current method:

  1. m_hasVisibleThreats requires the target to be within the SurvivorBot's FOV. This means that even if the manual_attack_mindot option is lower than 0.6, the SurvivorBots will ignore any target they can't see.
  2. If even one target is within the SurvivorBot's FOV, then your foreach statements would have to call the Left4Utils.CanTraceTo function for each target from their tables. Assuming a horde is currently active, the SurvivorBots would be performing numerous raycasts to every common infected within the specified radius which could negatively impact performance while in combat.

My proposed solution would be to remove the m_hasVisibleThreats and instead only call Left4Utils.CanTraceTo once for each of the nearest targets. This not only allows the manual_attack_mindot to work as intended, but it also optimizes performance since the Left4Bots.FindBotNearestEnemy function won't have to perform raycasts as often.

Here is the left4bots_afterload.nut file if you would like to test it out:

Manual Attack Adjustments.zip

smilz0 commented 8 months ago

Thanks, i will check this. Anyway, the idea for the future is to store the common infected entities in a table for faster retrieval like already did with the specials. This should also improve the FindBotNearestEnemy performance.

smilz0 commented 7 months ago

I checked your changes and maybe there is a problem with the FindBotNearestEnemy one. I might be wrong but the way you search for the special infected target makes the bots ignore a visible infected if an invisible one is closer. For example: if a special infected is 2 meters away from the bot but he is behind a wall and another one is 3 meters away and he is visible and ready to attack the bot, the bot will ignore the first one (correctly) because not visible but will also ignore the second one because he is not the closest one. The original code would select the second infected as target.

I'm sure that the function can be optimized but i wouldn't bother too much with that part because most of the times the trace check is not performed on all the infected. If you look at this line of code: if (dist <= radius && dist < minDist && botFacing.Dot(toEnt) >= minDot && !ent.IsGhost() && Left4Utils.CanTraceTo(bot, ent, tracemask_others)) the if has other conditions before the CanTraceTo, if those conditions are not met, che CanTrace isn't executed.

However you are right about m_hasVisibleThreats, it causes the bots to ignore the infected that are between the m_hasVisibleThreats fov and the manual_attack_mindot one when the latter is larger, so that change is needed. Thanks.

smilz0 commented 7 months ago

I implemented the second change. Thanks again.