.:: 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
Is there a better way to do these ?
Old
  (#1)
Rifleman
This user broke our rules and has been BANNED
 
Status: Offline
Posts: 128
Join Date: Sep 2004
Location: Mars
Default Is there a better way to do these ? - 08-11-2004

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 ?
  
Reply With Quote
Re: Is there a better way to do these ?
Old
  (#2)
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: Is there a better way to do these ? - 08-11-2004

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.



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: Is there a better way to do these ?
Old
  (#3)
Rifleman
This user broke our rules and has been BANNED
 
Status: Offline
Posts: 128
Join Date: Sep 2004
Location: Mars
Default Re: Is there a better way to do these ? - 08-11-2004

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
  
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