.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   JoeBot/RACC aiming (http://forums.bots-united.com/showthread.php?t=2383)

Whistler 30-07-2004 00:57

JoeBot/RACC aiming
 
I have found a problem when trying to use the JoeBot/RACC aiming code here...
Code:

      Vector v_deviation = vecDirection - pev->v_angle;
      ClampAngles(v_deviation);

      float turn_skill = 0.3 * m_iSkill / 100;

      // if bot is aiming at something, aim fast, else take our time...
      if (m_iAimFlags >= AIM_LASTENEMY)
        speed = 0.7 + turn_skill; // fast aim
      else if (m_iAimFlags <= AIM_CAMP && (m_iAimFlags & AIM_CAMP))
        speed = 0.1 + turn_skill / 4; // very slow aim if camping
      else
        speed = 0.2 + turn_skill / 2; // slow aim

      float da_deadly_math = exp(log(speed / 2) * g_iMsecval / 50);

      // Thanks Tobias Heimann and Johannes Lampel for this one
      pev->yaw_speed = (pev->yaw_speed * da_deadly_math + speed * v_deviation.y * (1 - da_deadly_math)) * g_iMsecval / 50;
      pev->pitch_speed = (pev->pitch_speed * da_deadly_math + speed * v_deviation.x * (1 - da_deadly_math)) * g_iMsecval / 50;

      // influence of y movement on x axis and vice versa (less influence than x on y since it's
      // easier and more natural for the bot to "move its mouse" horizontally than vertically)
      pev->pitch_speed += pev->yaw_speed / (1.5 * (1 + turn_skill));
      pev->yaw_speed += pev->pitch_speed / (1 + turn_skill);

+// If the fps is very low (e.g. when I'm running RealBot WIP and
+// bot with this code at the same time on my slow computer), the msec
+// value will be too large and the angle may exceed the deviation value. So
+// I've added a check here to prevent bots aiming from being messed up.
+// This seems to be "patching" but it works, also I have no clue about
+// the theory of the aiming algorithm :(
+      if (fabs(pev->pitch_speed) > fabs(v_deviation.x))
+        pev->pitch_speed = v_deviation.x;
+
+      if (fabs(pev->yaw_speed) > fabs(v_deviation.y))
+        pev->yaw_speed = v_deviation.y;

      pev->v_angle.y += pev->yaw_speed;
      pev->v_angle.x += pev->pitch_speed;


sPlOrYgOn 30-07-2004 02:24

Re: JoeBot/RACC aiming
 
well here's my version of it that also fixes the horrible aiming at very low fps..
Code:

    Vector vecDeviation = Vector (pEdict->v.idealpitch, pEdict->v.ideal_yaw, 0) - pBot->vecPrevv_angle;
      UTIL_ClampVector (&vecDeviation);

      float fAverageSpeed = 0;
      float fTurnSkill = pBot->bot_skill / 20.0 + 3.0;
      float fSpeed = 0;
      float fMultiplier = 1.0 / (2.0 * g_fFrameTime);
      if (fMultiplier > 25.0)
        fMultiplier = 25.0;
      if (fMultiplier < 2.0)
        fMultiplier = 2.0;

      if (pBot->iAimFlags & AIM_ENEMY)
        fSpeed = 0.7 + (fTurnSkill - 1.0) / 10.0; // fast aim
      else
        fSpeed = 0.2 + (fTurnSkill - 1.0) / 20.0; // slow aim

      pEdict->v.pitch_speed = (pEdict->v.pitch_speed * exp (log (fSpeed / 2) * g_fFrameTime * fMultiplier)
                              + fSpeed * vecDeviation.x * (1 - exp (log (fSpeed / 2) * g_fFrameTime * fMultiplier)))
                              * g_fFrameTime * fMultiplier;
      pEdict->v.yaw_speed = (pEdict->v.yaw_speed * exp (log (fSpeed / 2) * g_fFrameTime * fMultiplier)
                            + fSpeed * vecDeviation.y * (1 - exp (log (fSpeed / 2) * g_fFrameTime * fMultiplier)))
                            * g_fFrameTime * fMultiplier;

      // influence of y movement on x axis, based on skill (less influence than x on y since it's
      // easier and more natural for the bot to "move its mouse" horizontally than vertically)
      if (pEdict->v.pitch_speed > 0)
        pEdict->v.pitch_speed += pEdict->v.yaw_speed / (2.0 * (1 + fTurnSkill));
      else
        pEdict->v.pitch_speed -= pEdict->v.yaw_speed / (2.0 * (1 + fTurnSkill));

      // influence of x movement on y axis, based on skill
      if (pEdict->v.yaw_speed > 0)
        pEdict->v.yaw_speed += pEdict->v.pitch_speed / (1.5 * (1 + fTurnSkill));
      else
        pEdict->v.yaw_speed -= pEdict->v.pitch_speed / (1.5 * (1 + fTurnSkill));

      // Change Pitch Angles
      fAverageSpeed = (pBot->rgfPitchHistory[0] + pBot->rgfPitchHistory[1] + pEdict->v.pitch_speed) / 3;

      pBot->rgfPitchHistory[1] = pBot->rgfPitchHistory[0];
      pBot->rgfPitchHistory[0] = pEdict->v.pitch_speed;
 
      pEdict->v.v_angle.x += fAverageSpeed;

      // Change Yaw Angles
      fAverageSpeed = (pBot->rgfYawHistory[0] + pBot->rgfYawHistory[1] + pEdict->v.yaw_speed) / 3;

      pBot->rgfYawHistory[1] = pBot->rgfYawHistory[0];
      pBot->rgfYawHistory[0] = pEdict->v.yaw_speed;

      pEdict->v.v_angle.y += fAverageSpeed;

      // Save Angles
      pBot->vecPrevv_angle = pEdict->v.v_angle;
      UTIL_ClampVector (&pBot->vecPrevv_angle);

g_fFrameTime is just a manual version of gpGlobals->frametime because it seems booster modifies that one...

Pierre-Marie Baty 30-07-2004 15:53

Re: JoeBot/RACC aiming
 
This should rather be
Code:

+// If the fps is very low (e.g. when I'm running RealBot WIP and
+// bot with this code at the same time on my slow computer), the msec
+// value will be too large and the angle may exceed the deviation value. So
+// I've added a check here to prevent bots aiming from being messed up.
+// This seems to be "patching" but it works, also I have no clue about
+// the theory of the aiming algorithm :(
+          if (fabs(v_deviation.x - pev->pitch_speed) > 0)
+                pev->pitch_speed = v_deviation.x;
+
+          if (fabs(v_deviation.y - pev->yaw_speed) > 0)
+                pev->yaw_speed = v_deviation.y;

then, else you don't take care of the respective signs of v_deviation and aim speed, which can leads to a lot of problems in the aiming (like the bot able to get an instant headshot on new targets).

The drawback of this clamping is that it doesn't allow the bot's crosshair movement to get past the target point and then come back smoothly. I had it in in the first place, then I removed it, but I think I'm gonna put it back again because as you say it fixes the problem with the aim being messy at low FPS. Thanks for the reminder.

Whistler 01-08-2004 17:14

Re: JoeBot/RACC aiming
 
another correction:
Code:

      // if bot is aiming at something, aim fast, else take our time...
      if (m_iAimFlags >= AIM_LASTENEMY)
        speed = 0.7 + turn_skill; // fast aim
      else if (m_iAimFlags < AIM_PREDICTPATH && (m_iAimFlags & AIM_CAMP))
        speed = 0.1 + turn_skill / 4; // very slow aim if camping
      else
        speed = 0.2 + turn_skill / 2; // slow aim


Whistler 02-08-2004 09:37

Re: JoeBot/RACC aiming
 
Code:

+      if (fabs(v_deviation.x - pev->pitch_speed) > 0)
+        pev->pitch_speed = v_deviation.x;
+
+      if (fabs(v_deviation.y - pev->yaw_speed) > 0)
+        pev->yaw_speed = v_deviation.y;

...if you are doing this then bot will actually do inhuman turns all the time since as long as v_deviation.x isn't equal to pev->pitch_speed, fabs(v_deviation.x - pev->pitch_speed) will be >0. :)

Thanks to pointing this out anyway, now I have changed it to this one:
Code:

+      if (fabs(pev->pitch_speed) > fabs(v_deviation.x) && pev->pitch_speed * v_deviation.x > 0)
+        pev->pitch_speed = v_deviation.x;


Pierre-Marie Baty 02-08-2004 15:33

Re: JoeBot/RACC aiming
 
Yup, my bad 9_9

I forgot rule #1 of coding:
Untested code does not work.


All times are GMT +2. The time now is 18:16.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.