From: terencehill Date: Sun, 21 Aug 2022 17:04:27 +0000 (+0200) Subject: Bot AI: improve aim by refactoring max fire deviation formula, now more accurate... X-Git-Tag: xonotic-v0.8.6~322^2~11 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4ae6e27ee;p=xonotic%2Fxonotic-data.pk3dir.git Bot AI: improve aim by refactoring max fire deviation formula, now more accurate and scalable on any distance --- diff --git a/qcsrc/server/bot/default/aim.qc b/qcsrc/server/bot/default/aim.qc index 024db9237..31dc5af13 100644 --- a/qcsrc/server/bot/default/aim.qc +++ b/qcsrc/server/bot/default/aim.qc @@ -377,16 +377,18 @@ bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeed shotdir = v_forward; v = bot_shotlead(this.bot_aimtargorigin, this.bot_aimtargvelocity, shotspeed, this.bot_aimlatency); - distanceratio = sqrt(bound(0,skill,10000))*0.3*(vlen(v-shotorg)-100)/autocvar_bot_ai_aimskill_firetolerance_distdegrees; - distanceratio = bound(0,distanceratio,1); - float mindegrees = autocvar_bot_ai_aimskill_firetolerance_mindegrees; - float diffdegrees = autocvar_bot_ai_aimskill_firetolerance_maxdegrees - mindegrees; - if (!shot_accurate) // this shot doesn't require too much accuracy - mindegrees += diffdegrees * 0.25; - else // less skilled bots shoot even if they aren't aiming accurately - mindegrees += (random() > 0.3) ? 0 : diffdegrees * 0.25 * (1 - bound(0, skill / 10, 1)); - diffdegrees = autocvar_bot_ai_aimskill_firetolerance_maxdegrees - mindegrees; - float maxfiredeviation = diffdegrees * (1 - distanceratio) + mindegrees; + // this formula was created starting from empiric values of distance and max hit angle + // with a player as target (32 qu wide) from the center of it right in front of the bot + // distance: 32 50 75 100 150 200 300 400 500 + // max ang: 44 24 15.1 10.5 6.5 4.9 3.1 2.3 1.8 + float dist = max(10, vlen(v - shotorg)); + float maxfiredeviation = 1000 / (dist - 9) - 0.35; + + if (!shot_accurate) + maxfiredeviation *= 1.6; + else + maxfiredeviation *= 1 + bound(0, (10 - (skill + this.bot_aimskill)) * 0.3, 3); + maxfiredeviation = min(autocvar_bot_ai_aimskill_firetolerance_maxdegrees, maxfiredeviation); if (applygravity && this.bot_aimtarg) { diff --git a/qcsrc/server/bot/default/cvars.qh b/qcsrc/server/bot/default/cvars.qh index 4b3888986..43a92f6be 100644 --- a/qcsrc/server/bot/default/cvars.qh +++ b/qcsrc/server/bot/default/cvars.qh @@ -2,9 +2,7 @@ float autocvar_bot_ai_aimskill_blendrate; int autocvar_bot_ai_aimskill_firetolerance; -float autocvar_bot_ai_aimskill_firetolerance_distdegrees; float autocvar_bot_ai_aimskill_firetolerance_maxdegrees; -float autocvar_bot_ai_aimskill_firetolerance_mindegrees; float autocvar_bot_ai_aimskill_fixedrate; float autocvar_bot_ai_aimskill_mouse; float autocvar_bot_ai_aimskill_offset; diff --git a/xonotic-server.cfg b/xonotic-server.cfg index f4ef72241..e6bfecb83 100644 --- a/xonotic-server.cfg +++ b/xonotic-server.cfg @@ -139,8 +139,6 @@ set bot_ai_dangerdetectionupdates 64 "How many waypoints will be considered for set bot_ai_aimskill_blendrate 2 "How much correction will be applied to the aiming angle" set bot_ai_aimskill_fixedrate 15 "Distance based scale from which correction will be applied to the aiming angle" set bot_ai_aimskill_firetolerance 1 "enable fire tolerance" -set bot_ai_aimskill_firetolerance_distdegrees 100 "Rate at which the aiming angle is updated, scales by skill" -set bot_ai_aimskill_firetolerance_mindegrees 2 "Minimum angle tolerance. Used on large distances" set bot_ai_aimskill_firetolerance_maxdegrees 60 "Maximum firing angle. Used on close range" set bot_ai_aimskill_mouse 1 "How much of the aiming filters are applied" set bot_ai_keyboard_distance 250 "Keyboard emulation is disabled after this distance to the goal"