AI Tutorial
Improved Grenade Aiming

 

      Some tutorials can be long, and others shortish. this one is so short that you won't believe it. It's just one line of code!
      The Tutor bot has awful grenade aiming. This is a simple problem and simple to fix. Basically, no matter how high or low it's enemy is in relation to it's self, it will always fire the grenade at the same vertical height. That is, it doesn't aim up and down with grenades.
      Now we can't let our bots use the same aiming code as Ogres, can we! Lets open up tutor.qc, and scroll down to bot_fire_grenade, which begins like this:


// """"""""""""""""""""""""""""
void() bot_fire_grenade =
// ----------------------------
{
	local	entity missile;
	
	self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
	self.effects = self.effects | EF_MUZZLEFLASH;
	sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);

	missile = spawn ();
	missile.owner = self;
	missile.movetype = MOVETYPE_BOUNCE;
	missile.solid = SOLID_BBOX;
		
// set missile speed	
	makevectors (self.v_angle);

	missile.velocity = bot_aim_at_enemy();
	missile.velocity = missile.velocity * 500;
	missile.velocity_z = 300;

      That last line is the one we're looking for, the evil line which tells the bot to ignore the height difference. Change it to:

missile.velocity_z = missile.velocity_z + 200;

      Anyone with half a brain can see what i've done! Instead of reseting the Z velocity, I've just added to it, so it shoots to the right height, like a player would. Also, I changed the 300 to a 200, as that's what the player's grenade Z velocity is.
      That really is it! Compile it, and play on a level like DM1, where the bot can wreak hovoc with grenades!
 


What We Learned

1. Coffee likes using daft ogre code!
2. Only joking. We didn't learn anything really....


     Author: SkinSki
     Questions: [email protected]
     AI chat on ICQ: 30578982