View Single Post
Re: improving obstacle detection with trigonometry
Old
  (#4)
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: improving obstacle detection with trigonometry - 30-01-2004

Nevermind, it looks like I've found it myself me alone like a grownup
Code:
void BotCheckForObstaclesAtFeet (player_t *pPlayer)
{
   // this function returns an integer bitmap describing the presence and quality of any
   // obstacle right around the bot. Useful for low walls over which the bot has to jump,
   // or for determining if the bot should duck to pass a low ceiling. This function is
   // called every frame, systematically, in BotSense(), so that the bot knows, when
   // it starts thinking, the quality of the terrain in front of it. First it checks if
   // it is about to hit something when walking forward, and if so, it checks if the bot's
   // look hits a wall when looking straight horizontally. If so, then the bot might be
   // able to duck over something to pass by ; if not, then the bot might be able to
   // jump over the obstacle ; we do the appropriate checks.
   // NOTE: player's origin is 37 units above the ground (standing height)
   //	   player is 36 units high when ducking
   //	   max stair height is 18 units
   //	   max jump height is 45 units
   //	   max jump height is 63 units when doing a duck-jump
 
   TraceResult tr1, tr2, tr3, tr4, tr5;
   Vector v_feet;
   float angle_diff, check_distance;
   float left_check_dst, front_check_dst, right_check_dst;
 
   pPlayer->Bot.BotBody.hit_state = OBSTACLE_NONE; // first off, reset the hit state bitmap
 
   // given the bot's velocity, bot will check closer or further forward (range 60-120 units)
   check_distance = 0.4 * pPlayer->pEntity->v.velocity.Length2D ();
   angle_diff = UTIL_VecToAngles (pPlayer->pEntity->v.velocity).y - pPlayer->v_angle.y;
 
   // we gotta transpose this distance to both sides of the bot (and also forward)
 
   // left distance
   pPlayer->Bot.BotBody.left_check_dst = check_distance * sin (angle_diff);
   if (pPlayer->Bot.BotBody.left_check_dst < 60)
	  pPlayer->Bot.BotBody.left_check_dst = 60; // bound it to 60 units minimum
   else if (pPlayer->Bot.BotBody.left_check_dst > 120)
	  pPlayer->Bot.BotBody.left_check_dst = 120; // and 120 units maximum
 
   // forward distance
   pPlayer->Bot.BotBody.front_check_dst = check_distance * cos (angle_diff);
   if (pPlayer->Bot.BotBody.front_check_dst < 60)
	  pPlayer->Bot.BotBody.front_check_dst = 60; // bound it to 60 units minimum
   else if (pPlayer->Bot.BotBody.front_check_dst > 120)
	  pPlayer->Bot.BotBody.front_check_dst = 120; // and 120 units maximum
 
   // right distance
   pPlayer->Bot.BotBody.right_check_dst = check_distance * -sin (angle_diff);
   if (pPlayer->Bot.BotBody.right_check_dst < 60)
	  pPlayer->Bot.BotBody.right_check_dst = 60; // bound it to 60 units minimum
   else if (pPlayer->Bot.BotBody.right_check_dst > 120)
	  pPlayer->Bot.BotBody.right_check_dst = 120; // and 120 units maximum
 
   // get a quick access to these three
   left_check_dst = pPlayer->Bot.BotBody.left_check_dst;
   front_check_dst = pPlayer->Bot.BotBody.front_check_dst;
   right_check_dst = pPlayer->Bot.BotBody.right_check_dst;
 
   // rest of function follows...



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