Improved aiming

This commit is contained in:
ineedbots 2021-05-19 15:23:53 -06:00
parent c2c7b94c79
commit 7a0dc3b7f9

View File

@ -1394,7 +1394,7 @@ aim()
if (conedot > 0.999 && lengthsquared(aimoffset) < 0.05) if (conedot > 0.999 && lengthsquared(aimoffset) < 0.05)
self thread bot_lookat(aimpos, 0.05); self thread bot_lookat(aimpos, 0.05);
else else
self thread bot_lookat(aimpos, aimspeed); self thread bot_lookat(aimpos, aimspeed, target getVelocity());
} }
else else
{ {
@ -2327,7 +2327,7 @@ botMoveTo(where)
/* /*
Bots will look at the pos Bots will look at the pos
*/ */
bot_lookat(pos, time) bot_lookat(pos, time, vel)
{ {
self notify("bots_aim_overlap"); self notify("bots_aim_overlap");
self endon("bots_aim_overlap"); self endon("bots_aim_overlap");
@ -2342,12 +2342,23 @@ bot_lookat(pos, time)
if (!isDefined(pos)) if (!isDefined(pos))
return; return;
steps = time / 0.05; if (!isDefined(time))
if (!isDefined(steps) || steps <= 0) time = 0.05;
if (!isDefined(vel))
vel = (0, 0, 0);
steps = int(time * 20);
if (steps < 1)
steps = 1; steps = 1;
myEye = self GetEye(); // get our eye pos
myEye += (self getVelocity() * 0.05) * (steps - 1); // account for our velocity
pos += (vel * 0.05) * (steps - 1); // add the velocity vector
myAngle=self getPlayerAngles(); myAngle=self getPlayerAngles();
angles = VectorToAngles( (pos - self GetEye()) - anglesToForward(myAngle) ); angles = VectorToAngles( (pos - myEye) - anglesToForward(myAngle) );
X=(angles[0]-myAngle[0]); X=(angles[0]-myAngle[0]);
while(X > 170.0) while(X > 170.0)
@ -2361,7 +2372,6 @@ bot_lookat(pos, time)
Y=Y-360.0; Y=Y-360.0;
while(Y < -180.0) while(Y < -180.0)
Y=Y+360.0; Y=Y+360.0;
Y=Y/steps; Y=Y/steps;
for(i=0;i<steps;i++) for(i=0;i<steps;i++)