Inside3D!
     

Problem with ChangePitch()

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
Orion



Joined: 12 Jan 2007
Posts: 413
Location: Brazil

PostPosted: Thu Dec 24, 2009 6:17 pm    Post subject: Problem with ChangePitch() Reply with quote

Hi, I have a little problem with a ChangePitch() function I created, yes, Darkplaces has its own changepitch() builtin, but I made one to use with v_angle_x instead of angles_x.

Look:
Code:

void() Bot_ChangePitch =
{
   local float ideal, move, current;
   
   current = anglemod(self.v_angle_x);
   ideal = self.idealpitch;
   
   if (current == ideal)
      return;
   
   move = ideal - current;
   if (ideal > current)
   {
      if (move > 180)
         move = move - 360;
   }
   else
   {
      if (move < -180)
         move = move + 360;
   }
   
   if (move > 0)
   {
      if (move > 14.4)
         move = 14.4;
   }
   else
   {
      if (move < -14.4)
         move = -14.4;
   }
   
   current = anglemod (current + move);
   self.v_angle_x = current;
};


The function is exactly like ChangeYaw(), but the problem is:

When I play with the bots they have trouble aiming upwards, but downwards they work OK.

When they try to aim upwards I see them upside down, and then not shooting.

Here's my bot_aim() code:

Code:

void() bot_aim =
{
   local vector vel, spot, dir;
   local float go;
   
   if (self.weapon != IT_SHOTGUN && self.weapon != IT_SUPER_SHOTGUN && self.weapon != IT_LIGHTNING)
   {
      if (self.weapon == IT_GRENADE_LAUNCHER)
         go = vlen(self.enemy.origin - self.origin) / 800;
      else
         go = vlen(self.enemy.origin - self.origin) / 1000;
      
      vel = self.enemy.velocity;
      vel_z = 0;
      spot = self.enemy.origin + vel*go;
      
      traceline (self.origin, spot, FALSE, self);
      if (trace_fraction < 0.8)
         spot = self.enemy.origin;
         
      dir = normalize(spot - self.origin);
      dir = vectoangles(dir);
   }
   else
   {
      dir = self.enemy.origin - self.enemy.velocity*0.065;
      dir = normalize(dir - self.origin);
      dir = vectoangles(dir);
   }
   
   dir_x = dir_x * -1;
   while (dir_x > 180)
      dir_x = dir_x - 360;
   while (dir_x < -180)
      dir_x = dir_x + 360;
   
   self.idealpitch = dir_x;
   self.ideal_yaw = dir_y;
   
   if (self.turn_time < time)
   {
      Bot_ChangePitch ();
      Bot_ChangeYaw ();
      self.turn_time = time + 0.02;
   }
};


Any help appreciated.
_________________
There's no signature here. Stop looking for one.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group