Look:
Code: Select all
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;
};
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: Select all
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;
}
};