AI pawn to aim at player

I realize there must be much information on this in the UDK forums, but they’re currently down.

I’d like to know if there is existing code in UDK for ai controlled bots to aim at a player. Or even… calculate the velocity of the target, in order to fire a leading shot.

Any advice is greatly appreciated.

I code it myself, use whatever class is your player, there’s alot to it, find a target, chekc if its in range, check if its in melle range, move your bot to face the target, check if it will hit a friendly,



		ForEach AllActors(class'ImpiBot', pb)
		{
			if (pb.IsAliveAndWell())
			{	
// add to a list of a players, check distance etc, like if in mellee or gun range
                         }
                }

// after I find a target I do other stuff like check target visibilty, see they dont hit friendly (do a trace) etc once the bot has a target



simulated function Rotator GetAdjustedAimFor( Weapon W, vector StartFireLoc )
{
// I randomise it so the shots sometimes go left, right, high or low

// this may not compile quick extract from some of mine 

	local Rotator newrot;
	local float updRot;
	local int updDir;


	cosang = NoZDot(SoldierBot(Pawn).SoldierMarker.location , Normal(StartFireLoc));
	angbet = Acos(cosang);
	angbet = abs((32762/PI)*Acos(cosang));

	
		newrot = rotator(Enemy.location - StartFireLoc);

		if (!SoldierBot(Pawn).DefaultAttackFreq)
		{
			updDir = Rand(5); 
		}
		else
		{		
			updDir = Rand(4);  
		}

		updRot = Rand(adjWeapon);
			switch (updDir)
			{
				case (0):
					break;
				case (1):
					break;
				case (2):
					if (SoldierBot(Pawn).doFear)
					{				
						newrot.Yaw -= updRot;
					}
					break;
				case (3):				//direct shot if not scared
					if (SoldierBot(Pawn).doFear)
					{
						newrot.Pitch -= updRot;
					}
					break;
				case (4):
					newrot.Pitch -= updRot;
					break;
				case (5):
					newrot.Pitch -= updRot;
					break;					
			}
		}
		return newrot;

}


Thanks @Yummy-Vegetables. That helps a lot (especially with the UDK forums still being down).

I’m still curious how to handle firing a leading shot, based on the velocity of the target. Currently my bot always misses if i’m side-stepping.

Instead aiming to “player.location”, use “player.location + (player.velocity*factor)”. “Factor” can be a multiplier using “Player.location - Location” (the distance) and the projectile speed. I actually use this for the bows, and are enough acurate.

Awesome, thanks @CobaltUDK. I’ll give it a shot (no pun intended).