Today we have a rarity, a lesson which both simple and effective. As you know, I take shortcuts to teach you in the quickest way. But this tutorial is naturally easy and fully functional.
I remember when people made a big deal about the Omicron Bot's aiming, the fact that he would shoot at your last location and all that. Well, in a few minutes your bot will be able to do that and more. So there, Omicron.
We are going to do realistic aiming. That is, if you are one of those good players that move around alot, he will be shooting at your previous locations. If you are a stop-and-shoot kind of guy, he will nail you real good. In addition, there wil be ten -- count 'em, ten! -- different skill levels of bot aiming, from perfect to pathetic.
Unfortunately, we need three new variables to achieve this. As you may know, I am very system-conscious, and I normally don't like to use three variables for one simple feature. But of course, bot aiming is a critical feature. So open up defs.qc and drop to the bottom. There, add these lines:
.vector aim_location; .float aim_time; .float aim_delay;Alright, let me explain these and their roles in our new technique. The bot's aim_location is the point where he will shoot, regardless of where is enemy is standing in that instant. His aim_time is the next time he will refresh his aim_location, that is, make his aim_location the place where his foe is standing. And his aim_delay is the frequency at which he will do the refreshing.
// ------------------------------------- vector() bot_aim_at_enemy = // ------------------------------------- { return normalize(self.enemy.origin - self.origin); };As you can see, the bot shoots at the exact location of his enemy each and every frame. Let's change that to this:
// ------------------------------------- vector() bot_aim_at_enemy = // ------------------------------------- { if (time > self.aim_time) { self.aim_location = normalize(self.enemy.origin - self.origin); self.aim_time = time + self.aim_delay; } return self.aim_location; };Things are coming into focus now. As you can see, if his aim_time is expired, he aims directly at his foe. Then he sets his delay. If his aim_time has not expired, he shoots in the last spot he saw his enemy. Groovy, huh?
local float a; a = floor(random() * 10) + 1; self.aim_delay = a / 10;This is groovy too. We create a random number from one to 10. We divide it by ten. It ends up being a value from 0.1 to 1.0, or, in other words, from a tenth of a second to a second. This will be his aiming delay time.