Creating AI Bots with weapons
by CoderT · in Torque 3D Beginner · 11/16/2012 (8:58 pm) · 16 replies
Hi,
I have been following the "FPS tutorial" to try and make a simple fps type game.
However I haven't been able to reproduce what the tutorial writes about.
I have the ai bots spawning properly, coded that part myself. I even got them to hold weapons.
But this is where the trouble begins.
The rocket launcher that they have, they don't fire. They will aim at me etc etc but not fire at all. Although in the console I get all the messages from the ai routine, lets call it.
Then, when I spawn them with the normal machine gun, the Lurker. They will fire at me but only hit me from a 5m range. And really slow, couple seconds between shots. Kinda disappointing since i put so much work into it.
I'd really like some help to get this fixed.
Thanks.
I have been following the "FPS tutorial" to try and make a simple fps type game.
However I haven't been able to reproduce what the tutorial writes about.
I have the ai bots spawning properly, coded that part myself. I even got them to hold weapons.
But this is where the trouble begins.
The rocket launcher that they have, they don't fire. They will aim at me etc etc but not fire at all. Although in the console I get all the messages from the ai routine, lets call it.
Then, when I spawn them with the normal machine gun, the Lurker. They will fire at me but only hit me from a 5m range. And really slow, couple seconds between shots. Kinda disappointing since i put so much work into it.
I'd really like some help to get this fixed.
Thanks.
About the author
#2
Yea sure, here is the link: http://www.garagegames.com/community/resources/view/20829
11/17/2012 (12:32 am)
Thanks for the reply.Yea sure, here is the link: http://www.garagegames.com/community/resources/view/20829
#3
when I spawn them with the normal machine gun, the Lurker. ."
i belive u did not load them with rocket launcher ammo.they only have lurker ammo.
give them some rocket luncher ammo to fire to u.
" They will fire at me but only hit me from a 5m range. "
increase range value from condition.
for range prefer what u like but not higher then weapon's range.
in that case u have to increase weapon's range.
"really slow, couple seconds between shots. "
look into schedule()'s 1st parameter.
better if u post u r full code here.
11/17/2012 (1:34 am)
"The rocket launcher that they have, they don't fire.when I spawn them with the normal machine gun, the Lurker. ."
i belive u did not load them with rocket launcher ammo.they only have lurker ammo.
give them some rocket luncher ammo to fire to u.
" They will fire at me but only hit me from a 5m range. "
increase range value from condition.
for range prefer what u like but not higher then weapon's range.
in that case u have to increase weapon's range.
"really slow, couple seconds between shots. "
look into schedule()'s 1st parameter.
better if u post u r full code here.
#4
%weaponAmmo = "rocketAmmo";
%weaponImage = "rocketImage";
It seems more that they don't "hit" me than that the range is not enough.
As in they don't fire accurate enough. But I don't know where to change that, if that is the case.
The range that they can fire at me is 200m. So that should be plenty.
Is the schedule() also related to the bot's combat mode? Because the schedule function is supposed to be for its thinking. Not shooting.
The code I use for the rockets for example is an exact copy from the tutorial I posted earlier.
11/17/2012 (5:00 am)
No ammo get loaded by the equipt function. This for rockets:%weaponAmmo = "rocketAmmo";
%weaponImage = "rocketImage";
It seems more that they don't "hit" me than that the range is not enough.
As in they don't fire accurate enough. But I don't know where to change that, if that is the case.
The range that they can fire at me is 200m. So that should be plenty.
Is the schedule() also related to the bot's combat mode? Because the schedule function is supposed to be for its thinking. Not shooting.
The code I use for the rockets for example is an exact copy from the tutorial I posted earlier.
#5
If that doesn't work, try lowering the time in the schedule.
Does the AI player have any rocket ammo?
to
11/17/2012 (7:04 am)
I'll take a stab at this. I did this tutorial but I ripped out the shooting part.Quote:And really slow, couple seconds between shots.Try changing:
shootingDelay = 500;to
shootingDelay = 200;
If that doesn't work, try lowering the time in the schedule.
Quote:No ammo get loaded by the equipt function. This for rocketsIn the AI script, "equipBot" function. You have something like this?
%this.setInventory(rocket, 1); %this.setInventory(rocketAmmo, %this.maxInventory(rocketAmmo)); %this.mountimage(rocketImage, 0);
Does the AI player have any rocket ammo?
maxInv[rocketAmmo] = 20;
Quote:It seems more that they don't "hit" me than that the range is not enough.In AIPlayer::checkRange, I changed:
%rangeFrom = %this.range;
to
%rangeFrom = 25;
#6
%this.setInventory(%weapon, 1);
%this.setInventory(%weaponAmmo, %this.maxInventory(%weaponAmmo));
%this.mountimage(%weaponImage, 0);
Yes I have this as well in one of the datablock functions "maxInv[rocketAmmo] = 20;".
I'll try changing the shooting delay.
Doesn't the last part you posted about the range decrease it to 25m?
And I have another question. Can I add another parameter in the schedule function to pass to that function that it calls?
11/17/2012 (7:24 am)
Yes I have this in the equipt function:%this.setInventory(%weapon, 1);
%this.setInventory(%weaponAmmo, %this.maxInventory(%weaponAmmo));
%this.mountimage(%weaponImage, 0);
Yes I have this as well in one of the datablock functions "maxInv[rocketAmmo] = 20;".
I'll try changing the shooting delay.
Doesn't the last part you posted about the range decrease it to 25m?
And I have another question. Can I add another parameter in the schedule function to pass to that function that it calls?
#7
11/17/2012 (7:28 am)
Quote:Doesn't the last part you posted about the range decrease it to 25m?Yes, but you can change it.
#8
For every weapon? Not just a single one.
How could I set it say per weapon?
11/17/2012 (7:35 am)
Also, I suppose that if you set the delays etc it is global.For every weapon? Not just a single one.
How could I set it say per weapon?
#9
I suppose in AIPlayer you could do something like:
shootingDelay = %shotDelayVar;
then in your AIPlayer::equipBot, and under what weapon you want:
%shotDelayVar = 1000;
11/17/2012 (7:52 am)
It's global.I suppose in AIPlayer you could do something like:
shootingDelay = %shotDelayVar;
then in your AIPlayer::equipBot, and under what weapon you want:
%shotDelayVar = 1000;
#10
I do have another problem of the ai completely not being accurate. I did some searching and saw that there are alot of topics on that.
But what is the proper solution to it?
11/18/2012 (1:00 pm)
Alright, I have it sorted out. Still not working as expected but ok.I do have another problem of the ai completely not being accurate. I did some searching and saw that there are alot of topics on that.
But what is the proper solution to it?
#11
Universal AI Starter Kit
Tactical AI Kit
Guide Bot
11/18/2012 (1:17 pm)
I've never done too much with AI in genral. There are a few AI packs for Torque. If you were thinking of getting one of these, make sure they are still being supported.Universal AI Starter Kit
Tactical AI Kit
Guide Bot
#12
If you're seeing a constant offset, try playing with the offset parameter of setAimObject:
If the bots aren't leading their target correctly, you'll have a bit more trouble accounting for it.
11/18/2012 (1:57 pm)
What do you mean by inaccurate? Do they shoot at a slight offset from the actual target? Or do they not account for the target moving?If you're seeing a constant offset, try playing with the offset parameter of setAimObject:
%aiplayer.setAimObject(%player, "0 0 1.5");Also look at the images they're shooting with. There should be a correctMuzzleVector setting that should make them more accurate.
If the bots aren't leading their target correctly, you'll have a bit more trouble accounting for it.
#13
But they do account for moving targets. At least thus far.
I tried using the "0 0 1.5" but it seems to make absolutely no difference.
They just won't hit me passed about 3-5m. They hit the wall behind me which is how I can determine how far off their aim is.
11/19/2012 (1:38 am)
Yes they shoot with a slight offset near the target. Usually to the side and often up.But they do account for moving targets. At least thus far.
I tried using the "0 0 1.5" but it seems to make absolutely no difference.
They just won't hit me passed about 3-5m. They hit the wall behind me which is how I can determine how far off their aim is.
#14
time - Number of milliseconds to wait before calling the command.
command - Member function (belonging to the simObject using schedule) to call
arg1...argN - Parameters, comma separated, to pass into the command.
so -
will pass %x, %y, %z and %anythingElse to your %myCoolBot.shoot() function in the order given.
11/19/2012 (5:08 pm)
Schedule (ConsoleMethod) ParameterssimObject.schedule(time, command, arg1...argN);
time - Number of milliseconds to wait before calling the command.
command - Member function (belonging to the simObject using schedule) to call
arg1...argN - Parameters, comma separated, to pass into the command.
so -
%myCoolBot.schedule(150, shoot, %x, %y, %z, %anythingElse);
will pass %x, %y, %z and %anythingElse to your %myCoolBot.shoot() function in the order given.
#15
11/20/2012 (12:43 am)
So what do I about the accuracy problem then?
#16
The resource covers getting AI opponents working with Recast/Detour in the Chinatown map. He links to the resource covering getting Recast/Detour working as well.
What you're looking for is on that page about 1/3 of the way down - you can search that page for AiLurkerWeaponImage to find the exact code block.
11/20/2012 (12:41 pm)
Ok, I went digging because I knew that I had seen Steve post about it and I found his Chinatown AI Deathmatch free-for-all resource.The resource covers getting AI opponents working with Recast/Detour in the Chinatown map. He links to the resource covering getting Recast/Detour working as well.
What you're looking for is on that page about 1/3 of the way down - you can search that page for AiLurkerWeaponImage to find the exact code block.
Associate Britt Scott