Game Development Community

AI not firing accurately

by Jinnie Ong · in Torque 3D Professional · 03/30/2010 (10:15 pm) · 3 replies

I created a set of new weapons and loaded them on to an AI character. However, when I asked that character to aim at another character and fire, he always seems to be shooting to the left of the target and not right on the target.

The common problem most people face is that the AI is firing at the foot of the target, however my characters seem to be off-target by a certain amount which appears to be dependent on the gun.

Meaning manually offsetting the aim will correct one weapon, but cause another to miss. Anyone knows the cause of this? Thanks!

#1
03/31/2010 (7:14 am)
%your_AI.setAimobject(%the_target,"0 0 1.5");
Should have your AI aiming at chest height. If you've got it aiming elsewhere then it's probably due to how it's animated, and the position/rotation of it's bones are not straight-on. If you can give the weapons a correctmuzzlevector=1; then do, and if that doesn't help try giving the weapons an eyeoffset with the first value as 0(eyeOffset = "0.0 0.1 -0.2";).
#2
03/31/2010 (7:35 am)
That might explain things. I currently have my eyeOffset with the first value being 0.6. Putting it to 0.0 does seem to solve the problem. However that makes weapons in first person appear right smack in the middle of the screen as opposed to being on the side.

One solution is to make two sets of weapons. One for AI, another for the player... but is that really necessary?
#3
03/31/2010 (11:49 am)
correctmuzzlevector=1 should solve your problem, in theory. At least, it does for weapons being used by the player in first person. I would assume that AIPlayers are always supposedly in first person, so it should work for them as well. What this does is calculate the vector required to send the projectile from the actual muzzle point to the point in the world the player object's "eye" is looking at.

Set this in the weapon image datablock. By default it works at up to 500 units -- you may need to make a small adjustment to the raycast in code if your AIPlayers are snipers or your battlefields are just extremely large.