.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Bot Coding (http://forums.bots-united.com/forumdisplay.php?f=24)
-   -   Is there a better way to do these ? (http://forums.bots-united.com/showthread.php?t=2936)

Rifleman 08-11-2004 04:34

Is there a better way to do these ?
 
Here's some messy code ....

Code:

  if (pBot->strafe_left_time > gpGlobals->time)
  {
        pBot->f_move_speed = 0.0;
        pBot->f_sidemove_speed = -pBot->f_max_speed;
  }
  if (pBot->strafe_right_time > gpGlobals->time)
  {
        pBot->f_move_speed = 0.0;
        pBot->f_sidemove_speed = pBot->f_max_speed;
  }
  if (pBot->move_front_time > gpGlobals->time)
  {
        pBot->f_move_speed = pBot->f_max_speed;
        pBot->f_sidemove_speed = 0.0;
  }
  if (pBot->move_back_time > gpGlobals->time)
  {
        pBot->f_move_speed = -pBot->f_max_speed;
        pBot->f_sidemove_speed = 0.0;
  }
  if (pBot->north_east_time > gpGlobals->time)
  {
        pBot->f_move_speed = pBot->f_max_speed;
        pBot->f_sidemove_speed = pBot->f_max_speed;
  }
  if (pBot->south_east_time > gpGlobals->time)
  {
        pBot->f_move_speed = -pBot->f_max_speed;
        pBot->f_sidemove_speed = pBot->f_max_speed;
  }
  if (pBot->north_west_time > gpGlobals->time)
  {
        pBot->f_move_speed = pBot->f_max_speed;
        pBot->f_sidemove_speed = -pBot->f_max_speed;
  }
  if (pBot->south_west_time > gpGlobals->time)
  {
        pBot->f_move_speed = -pBot->f_max_speed;
        pBot->f_sidemove_speed = -pBot->f_max_speed;
  }

I think these dont need to explain

And the real messy ...

Code:

  Vector v_direction = pBot->waypoint_origin - pEdict->v.origin;
 
  Vector bot_angles = UTIL_VecToAngles(v_direction);
 
  int yaw = pEdict->v.ideal_yaw;
 
  while (yaw <= 0)
        yaw += 360;
 
  while (bot_angles.y <= 0)
        bot_angles.y += 360;
 
  int angle = yaw - bot_angles.y;
 
  while (angle > 180)
        angle -= 360;
 
        bot_angles = UTIL_VecToAngles( v_direction );
 
          UTIL_MakeVectors( pEdict->v.v_angle );
 
  // Check for correct angle and strafe for the correct direction
  // Waypoint at front
  if ((angle >= 0) && (angle < 22.5) ||
        (angle <= 0) && (angle > -22.5))
  {
        pBot->move_front_time = gpGlobals->time + 1.0;
  }
  // Waypoint at north-east
  else if ((angle >= 22.5) && (angle < 67.5))
  {
        pBot->north_east_time = gpGlobals->time + 1.0;
  }
  // Waypoint at right
  else if ((angle >= 67.5) && (angle < 112.5))
  {
        pBot->strafe_right_time = gpGlobals->time + 1.0;
  }
  // Waypoint at south-east
  else if ((angle >= 112.5) && (angle < 157.5))
  {
        pBot->south_east_time = gpGlobals->time + 1.0;
  }
  // Waypoint at back
  else if ((angle >= 0) && (angle > 157.5) ||
        (angle <= 0) && (angle < -157.5))
  {
        pBot->move_back_time = gpGlobals->time + 1.0;
  }
  // Waypoint at north-west
  else if ((angle <= -22.5) && (angle > -67.5))
  {
        pBot->north_west_time = gpGlobals->time + 1.0;
  }
  // Waypoint at left
  else if ((angle <= -67.5) && (angle > -112.5))
  {
        pBot->strafe_left_time = gpGlobals->time + 1.0;
  }
  // Waypoint at south-west
  else if ((angle <= -112.5) && (angle > -157.5))
  {
        pBot->south_west_time = gpGlobals->time + 1.0;
  }
  BotFixIdealYaw(pEdict);

These code is quite easy to understand , but , Is there a better way to do all these stuff ?

Pierre-Marie Baty 08-11-2004 16:10

Re: Is there a better way to do these ?
 
Yes

Easy way (but not human-like IMO): separate body angles and view angles - that's what 99% of the bot makers do.

Or if you want to continue that way, decrease the movement times. Putting gpGlobals->time + 1.0 means that as long as the waypoint will be in that particular direction, the bot will keep pressing that key, but also as soon as the waypoint turns to be in another direction, the bot will still be pressing the same key for 1 second. Reduce that to 0.2 or 0.1 second (depending on your frame time). You can use these values as reaction times too, like I do.

Rifleman 08-11-2004 16:19

Re: Is there a better way to do these ?
 
Quote:

Originally Posted by Pierre-Marie Baty
Easy way (but not human-like IMO): separate body angles and view angles - that's what 99% of the bot makers do.

Some examples ? I'm quite a n00b so please dont blame me on that :(
Is it like the PODBot navigation ?

Quote:

Or if you want to continue that way, decrease the movement times. Putting gpGlobals->time + 1.0 means that as long as the waypoint will be in that particular direction, the bot will keep pressing that key, but also as soon as the waypoint turns to be in another direction, the bot will still be pressing the same key for 1 second. Reduce that to 0.2 or 0.1 second (depending on your frame time). You can use these values as reaction times too, like I do.
Forget to tell you , I keep track the current waypoint distance from the bot , once it reach a specific distance , I reset all those strafing time to zero so there wont be much problem , but the biggest problem I have with this code is , the strafing is not accurate , like angle between "22.5" and "67.5" are consider as "north-east" and the bot may will strafe not very well :(


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

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