From 9cb2727fef579e021aceaa85c991956289dd6cd8 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Mon, 14 Sep 2026 23:25:50 +0200 Subject: [PATCH] feat(SNNBot): distance-adaptive aim smoothing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Far targets need more smoothing (small jitter = big miss at distance). Close targets need less (fast tracking). Linear ramp α=0.3..0.9 over 0..600 units. Co-Authored-By: Claude Opus 4.6 --- SNNBot_garage/src/SNNBot.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/SNNBot_garage/src/SNNBot.nim b/SNNBot_garage/src/SNNBot.nim index c83a373..de9781b 100644 --- a/SNNBot_garage/src/SNNBot.nim +++ b/SNNBot_garage/src/SNNBot.nim @@ -46,6 +46,9 @@ const # ponytail: uniform exploration noise; upgrade to annealed Gaussian if convergence needs tuning FIRE_POWER = 1.0 # fixed firing power; bullet speed = 20 - 3*FIRE_POWER BULLET_SPEED = 20.0 - 3.0 * FIRE_POWER + AIM_SMOOTH_MIN = 0.3 # close range — responsive + AIM_SMOOTH_MAX = 0.9 # long range — heavy smoothing + SMOOTH_DIST_MAX = 600.0 # distance at which max smoothing kicks in # ── SNN types ───────────────────────────────────────────────────────────────── @@ -345,11 +348,12 @@ method run*(bot: SNNBot) = let binInput = toBinaryInput(relBearing, bot.velDirDeg, bot.velSpeed, bot.hasLastPos) let winBin = bot.res.forward(binInput) let aimAngle = bot.res.interpolatedAngle(winBin) - const AIM_SMOOTH = 0.6 # 60% old, 40% new — dampens flicker - # ponytail: AIM_SMOOTH=0.6 balances tracking vs stability; lower if gun lags, raise if gun dances + # Far → more smoothing (less jitter). Close → less smoothing (faster tracking). + # ponytail: linear ramp; tune MIN/MAX if gun lags close or jitters far + let alpha = clamp(bot.enemyDist / SMOOTH_DIST_MAX, AIM_SMOOTH_MIN, AIM_SMOOTH_MAX) let aimRad = degToRad(aimAngle) - bot.smoothSin = AIM_SMOOTH * bot.smoothSin + (1.0 - AIM_SMOOTH) * sin(aimRad) - bot.smoothCos = AIM_SMOOTH * bot.smoothCos + (1.0 - AIM_SMOOTH) * cos(aimRad) + bot.smoothSin = alpha * bot.smoothSin + (1.0 - alpha) * sin(aimRad) + bot.smoothCos = alpha * bot.smoothCos + (1.0 - alpha) * cos(aimRad) let smoothedAim = radToDeg(arctan2(bot.smoothSin, bot.smoothCos)) bot.lastBinInput = binInput bot.targetAngle = gunDir + smoothedAim