Game Development Community

dev|Pro Game Development Curriculum

Tactical AI Kit: More Good Stuff!

by Bryce · 07/23/2009 (12:53 pm) · 18 comments

Hey everyone!

Been a while since I posted a blog here...*checks* Wow. Since May.

Anyway...I've had a lot going on regarding my fun little project. I'm finally finished writing documentation for the Torque3D port of it, and while I wait on a few other things, I've got some new features to showcase here.

Grenade Tossing
Finally got grenade throwing fixed! I had a very basic system for it last year (I think I mentioned it in one of my blogs from a while back), but it was absolutely terrible. They managed to blow themselves up more than the enemy.

Inspired by a Killzone AI article I've read (This), I implemented a new grenade toss function that uses navigation nodes around the target. When an NPC wants to grenade an enemy, he looks at the navigation nodes within the blast radius of that enemy, and weighs them all according to distance to the enemy and line of sight. The most desirable node gets a grenade thrown at it. They have not blown themselves up once.

This only works when the thrower is level with the node that he wants a grenade thrown at, because I'm not entirely sure how to figure out angles and velocities to throw things above and below...I'm not very inclined to figure out ballistics programming, but hopefully someone has an idea (tgeBryce@yahoo.com if you've got tips).

img24.imageshack.us/img24/8181/61207402.png
Patrol Path Following
In a successful effort to make my levels more interesting, I added a patrol path functionality. You can create a path within the mission editor and assign it to a spawn point for an NPC to follow. Each marker can be given properties that control how fast an NPC will move to it, how long they will wait at that node, and what happens when they arrive there (have the NPC play an animation, or trigger a big explosion somewhere, etc.). It's not hard to dream up some good use for this

Snipers in a tower, moving from corner to corner...
Patrols on the street who find the body of someone you killed earlier...
A guard walking cautiously over to a suspicious (booby-trapped) vehicle, which explodes when he arrives...

img12.imageshack.us/img12/1019/83950832.png
Performance Improvements
I've been also working on improving the performance on the AI, especially in the wide-open maps without the spawn triggers (like the non-linear Middle East mission in the last demo). My laptop uses the Intel chip to handle graphics, so things get choppy when I have more than 6 in-game at once.

The middle east mission runs slowly for me because it's not only rendering dozens of (horribly LOD'ed) buildings, cars, trees, barrels, and players...it's also running over 30 AI think ticks per second, processing all the players around them, waiting for something interesting to happen.

I decided that to combat this issue, I would create an AI Manager that could actually, well, manage AI... The new AI Manager looks over each NPC in the mission every second, and figures out which ones are at risk of being seen by an opposing team member. NPCs that probably won't be in play won't be active, and will be set to “sleep.” A sleeping NPC will think just once every five seconds.

When they come under fire, they wake up and react accordingly. If they hear gunfire or find a body, they will stay asleep until the AI Manager decides they should wake up. This system will probably be most useful in single player missions...A developer (with a good graphics card) would be able to toss in 30 to 40 NPCs in their mission at once, and they will only be part of the gameplay when they should be.

(NPCs in this image have "zzz" over their head to show that they're asleep...I wasn't all that sure how I'd make a screenshot out of this feature.)
img12.imageshack.us/img12/9056/92913562.png
Leave a comment. I'm always open to questions and criticism!

#1
07/23/2009 (1:26 pm)
Sleeping guards :D

Good thinking on your part!
#2
07/23/2009 (1:56 pm)
Very nice blog, bryce. I was wondering the other day what was up with this project.

Putting your NPCs to sleep is a very clever way of saving bandwidth and CPU cycles. If you wanted to add some further optimization, you could set zones and spawn NPCs in the active and adjacent zones only, and despawn others. (This would probably need some more thinking though.)

If you don't want to use zones, you could just despawn anything that is outside of any client's view / cull distance and has no path that crosses this range (with the player in the center of course). Since the player continuously moves, you could set timers to despawn an out-of-range enemy - just in case it needs to be respawned within seconds, because the player moves right back into range - then you wouldn't want to despawn it just yet (leaving room for some aimless wandering).

This is what I do in Xenocell to stream in mob groups that use AI and path finding extensively. I also give more think frequency to NPCs that are closer, and less to those that are farther away (distance is relative to a game/genre, but it also saves you some resources). NPC behavior also affects think frequency. This system is tailored to stand ground in an MMO, but I guess it can never hurt to be able to handle more thinking NPCs in any kind of game.

You've been doing some amazing things with this, I can't wait to read more about it!
#3
07/23/2009 (1:57 pm)
When they wake up, do exclamation points appear?
If not I'm horribly dissapointed :P
Looking pretty sweet though.
#4
07/23/2009 (2:50 pm)
@Konrad: I may look into zones....I'd imagine that could be done with simple triggers, even!

@Jeff: They're not literally sleeping ;) The idea is that the player should RARELY have line of sight with a 'sleeping' NPC for more than a second, so no visible exclamation...That would be fun to have, though!
#5
07/23/2009 (2:56 pm)
I think Jeff was referring to the attention state in Metal Gear Solid! :) Cool idea!
#6
07/23/2009 (4:14 pm)
Just wondering when or if this is going to be in the store sometime soon? I have been following your progress and trying the demos, I know I am sold.
#7
07/23/2009 (4:19 pm)
Looks like you're coming on nicely!

As for sleepy AI, I had an idea about dividing the level into zones of triggers and using a script which basically fires when the player enters, collects the IDs of AIs within other predefined triggers and then tells them to turn off or on. In your case it'd mean more work for the level/gameplay scripter, but they should already being expecting that.

Also for grenade tossing. Remember that you can have your AI aim higher than the target. If you can work out aim heights at various ranges to take in the arc of the throw, you should have something vaguely realistic. Throwing isn't a science it's a hap-hazard art.
#8
07/23/2009 (5:50 pm)
@Konrad: Ahhhh of course! How did I not catch that...
@Ron: I haven't been to sure lately...I'm going to try to get an email out to one of the associates to ask them how to get a product up in the store. I've been beginning to learn about the lawyer fees involved in getting a product copyrighted. I'm not exactly sure yet how I'm going to get this sold
#9
07/23/2009 (5:51 pm)
For getting grenades thrown where you want, how you want them, this may help: http://www.garagegames.com/community/resources/view/14749
Since it's an iterator, you could potentially have nearby AI(that are likely to throw a nade after a friend) to check how the first throw goes, and get more accurate the more nades are thrown. At least for higher difficulties :P
It would technically apply for sniping AI as well, so they may botch the first shot or two, but if you stand around like a fool, they'll get you eventually :D
#10
07/23/2009 (8:35 pm)
Looking better and better everytime, still can't wait for the finished product!
#11
07/23/2009 (10:00 pm)
Quote:
I'm going to try to get an email out to one of the associates to ask them how to get a product up in the store.
You would want to talk to Derek
#12
07/23/2009 (10:04 pm)
a. maybe you can spawn/unspawn bots only when a player enter a trigger, with this you save memory and processor.

b. maybe if you put AI or each bot in another thread?, different of main thread. tdn.garagegames.com/wiki/Torque/1.4/MultiThread or Intel resources...

c. maybe In each "think" bot cicle, make a spherical raycast and if found and enemy continue the logic, if not sleep to the next think cicle.
#13
07/24/2009 (6:34 am)
looking very interesting Bryce :)

I wonder, have you considered amalgamating this with other addons ?

In particular I'm thinking of the GMK
www.garagegames.com/community/blogs/view/17843

They have some basic AI, I think these 2 projects would work
excellent together.. Yuri is a very nice guy, they have already
worked with BrokeAss Games to implemented usability for their
character packs.. worth an e-mail I think :)

#14
07/24/2009 (9:26 am)
Great that you got the grenade tossing right, now people can't hide behind covers for too long.
Sleeping sounds great, fast AI is always good.
Anyway, TAIK is stille looking really great. I hope you get it released fine at GG store.
#15
07/24/2009 (1:10 pm)
@ Bryce: For copyrighting something, you don't need to get a lawyer to do it. You can do it online from the Copyright Office (which is actually there perfered method). And there is a simple easy to fill out form, and then you can just zip up your files and upload them to the copyright office's servers.

www.copyright.gov
#16
07/24/2009 (7:54 pm)
@Hewster: Personally I think the TAIK should be incorporated with the resources that each individual feels are required for there own project and should be as barebones as possible.

+ the makers of GMK are already making an AI for T3D... I say us TGE'ers need some powerful AI more then all you "brand new engine" techies... >:)


@Stephen: useful info, good to know!

@Bryce: Good Luck getting this into the GG Store, this will be in my engine very shortly after it hits the store... given a reasonable price... and reasonable as in im pretty much broke all the time... :)
#17
07/24/2009 (9:22 pm)
@Tuomas: Cover will become even less safe once I work up some flanking behavior tomorrow :D

@Stephen: Thank you very much! I'll look into it

@CSMP: I'm thinking around $50 for a copy?

By the way, I've got it ported to T3D, so the "new engine" kids will be able to mess around with this as well ;)
My computer unfortunately cannot do advanced lighting above 1 frame per second... So I won't be able to have the good-graphics firefight I've dreamed of, but hopefully somebody can get this working with some good art! I can't wait for someone to pull off Call of Torque
#18
07/26/2009 (4:24 am)
That sounds pretty reasonable.

Hopefully I have the money available when you get this in the GG Store, because I cant wait to use the TAIK!