.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Bot Coding
General Bot Coding See what a pain it is to get those little mechs shooting around

Reply
 
Thread Tools
JoeBot/RACC aiming
Old
  (#1)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default JoeBot/RACC aiming - 30-07-2004

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;
  
Reply With Quote
Re: JoeBot/RACC aiming
Old
  (#2)
sPlOrYgOn
<-- He did it.
 
sPlOrYgOn's Avatar
 
Status: Offline
Posts: 1,558
Join Date: Jan 2004
Location: Los Angeles, California, USA, North America, Earth, Solar System, Milky Way.
Default Re: JoeBot/RACC aiming - 30-07-2004

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...
  
Reply With Quote
Re: JoeBot/RACC aiming
Old
  (#3)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: JoeBot/RACC aiming - 30-07-2004

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.



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: JoeBot/RACC aiming
Old
  (#4)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: JoeBot/RACC aiming - 01-08-2004

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
  
Reply With Quote
Re: JoeBot/RACC aiming
Old
  (#5)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: JoeBot/RACC aiming - 02-08-2004

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;
  
Reply With Quote
Re: JoeBot/RACC aiming
Old
  (#6)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: JoeBot/RACC aiming - 02-08-2004

Yup, my bad 9_9

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



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com