Game Development Community

Mark Holcomb's AIGuard Questions

by Ron Kapaun · in Technical Issues · 12/27/2007 (8:04 am) · 10 replies

Hey all,


I've been working with Torque for quite some time (since 2002 or so) and well I am finally at the point where I am working on some AI for my game. I really like Mark's AIGuard code because I understand how it works to a certain degree and have managed to alter it to do some good stuff. I was wondering...and yes I have looked through the AI section about 1000 times, if someone could explain HOW to expand a bit on this state engine? My biggest issue with it is the guards just standing there when they are getting shot. I would like them to be able to find cover and basically hide if they are taking damage. I have seen other code snips where they perform a raycast to locate "cover" in the AI's general Area but I have not been able to implement that into Mark's code at all. Anyone got an example of this that would work with Mark's script base? Or do I have to expand on the C++ section of his code to add this? Any help would be WONDERFUL! I think once I understand this aspect I should be able to manage more interesting "actions" instead of the code's stock "run and gun" idea. Additionally, I tried using a system similar to the "find health" and "find ammo" functions but for some reason I just can't seem to get my head around the raycast thing. Thanks in advance.


Ron

#1
12/27/2007 (12:50 pm)
I don't use AI Guard it was too messy for me.

Regardless, if you don't want them to just stand there getting shot, add some code to your onDamage callback for your AI that tells them to attack whoever attacks them.

Be careful though, if you don't do some checks they might start attacking each other.

Finding cover is MUCH harder to implement.
#2
12/27/2007 (6:08 pm)
There is a thread that talks about finding cover right here : http://www.garagegames.com/mg/forums/result.thread.php?qt=62670
(you have to scroll all the way down for the code)

I couldn't use the AI Guard resource because i don't have a compiler :-(. So instead i used the AIPlayer resource :-). I fixed it so that when the player is within 30 units around the bot, the bot sidesteps. When the attacker is running away, or is a certain distance away from the bot, the bot will follow the attacker.I also made it so that when the bot has low health, it'll find cover and heal. You can also do what Brian said, make the bot find cover when it is under attacked.

Or you can make the bot react to sound. For example, the bot hears an explosion/gunshot nearby, it will look for cover. If the explosion is faraway, but still can be heard, the bot will move to the spot where it heard that explosion.

Hopes this answers your question.

Jamal
#3
12/27/2007 (8:10 pm)
Why don't you use Microsoft visual studio express for your compiler its free.
#4
12/27/2007 (8:46 pm)
I did use the trial version a long time ago, and my computer was really REALLY bad. When I build, it freezes right in the middle. I just recently got a computer (which works ALOT better) but by then, the trial expired...

Jamal
#5
12/28/2007 (5:20 am)
It's not a trial. It's a full compiler/IDE suite. It lacks some of the extremely nifty features of the professional version (remote debugging, etc), but for a straight compile and go solution, it's great.
#6
12/28/2007 (6:20 am)
I've been working on AI players that DO successfully find and fire from cover and can sense when they're being shot at. I'll release the code as a resource soon, I just need to clean it up a little and fix the pathfinding. It's all scripted, too, so no compiling necessary (yet, I should probably move AStar pathfinding into C++ for performance).

By the way, Visual Studio is free, when the trail expires you just register for free on the Microsoft website (Visual Studio gives you a link).
#7
12/29/2007 (9:11 am)
Thanks People!

BrYce I got your script pieces crammed into Mark's Resource and it works pretty well. Took a bit of work but so far it is well worth the effort. In fact I even made a new class of AI based off it. Instead of a "Guard" unit it's more like a tactical unit that moves from one piece of cover to the next checking to see if it can "see" the player unit as it moves and waits. Bit wonky at the moment as I am using the Mission Area as it's boundary....so it can end up completely out in the middle of nowhere sometimes...Think I can fix that by defining a Maximum distance from the AI's drop point. Basically tell it to turn around once the distance value is greater or equal to the distance from it's drop. Turns out that I was able to add a "covering fire" type of action as well. So that the AI fires off some rounds as its moving to cover. Pretty niffty actually.

I just need to figure out a way for the AI to check the Player's line of sight. every once in a while they get near a "cover" object and they think they are "covered" when in fact they are still in the player's line of sight. Any suggestions on how to obtain the players LOS and check it against the cover position? Seems to me there was a segment in Killer Kork that grabbed the line of sight and caused the AI to avoid staying in the player's LOS. I will look into that later this afternoon. Or perhaps someone here has a more efficient way of doing that?
#8
12/29/2007 (3:18 pm)
@BrYcE - Thanks, I was too lazy to check my e-mail :-). Now i found it but i have to make an account for Microsoft, which I am about to do.

@Ron - I had a similar problem as well. I am trying to fix it, but every time I type "%this." or "player", Torsion freezes and then crashes (I just sent a bug report). Even if i write the code in Microsoft Word and then paste it into AIPlayer.cs, it still crashes. :-(

But, you can also try to give the bot a 360 degree vision when it reached it's destination. Then you can create an if statement to check it's LOS and if the target is in view.

if(%this.Istargetinview(%obj, %tgt, %obj.fov) && %this.CheckLOS(%obj, %tgt))

Then schedule the bot to "think" or find cover.

Unfortunately, I don't know how to check the player's LOS. But my best guess is to use "getEyeTransform" and then make a ray cast from the eye. If it hits the bot, make the bot find cover.

P.S. I doubt it'll work, but I'll try it out if Torsion STOPS crashing.

Jamal
#9
12/29/2007 (7:18 pm)
Actually Jamal that gives me an idea. And it points out my biggest common mistake when I am coding. I am always thinking in one particular way when there are usually multiple ways to accomplish things.

Your right of course. If the AI can not see me then I probably can not see the AI.

Oh yeah I would help with Torsion but I never bought it. Been using Codeweaver and textpad forever. But I hope ya get it sorted out.
#10
12/29/2007 (8:16 pm)
Glad I can help :-).