The Ultimate AI Script.

Hokay… we all know that as much as we want to make games, if we want to include an antagonist of some sort to the player, there is a need for at the very least a basic AI system.

i’ve tinkered with AI scripts here and other places and made one which i posted elsewhere here (link to forum post Here:-- http://forum.unity3d.com/threads/64971-Matrix-Variables-for-Multiplayer-Aggro-AI ) and though it works for a very basic, single-minded AI system (find player, go to player/follow player) it isn’t the most polished. it would work for things like basic turrets (if you freeze the movement) and is rather flexible (i’ve even used it to control the pyrokinesis “seeds” and with the right physics settings, acts relatively believable.)

thing is, i KNOW that this is the most basic of AIs that are out there… and i also know that good AI scripts are what can make your game from “good” to “WOAH!!!”

so, i propose this… a collaboration to help break down what basic principles are needed and how they would be implemented. this is for my own benefeit too since i’m trying to work out a good AI system (since the enemies in the game i am making aren’t as dumb as a brick wall.)

… so, here’s what i’ve got so far.

so… i know that this is likely not going to attract all you coders out there since some of you have some amazing scripts up for sale and aren’t really keen on releasing the secrets to how you did it… but that’s okay too. (we all have motives after all.)

so… first things first… in your opinion, would it be easier to use Java or C# (or is that merely a matter of preference?)

(using the Hulk as an example… but, ya gotta admit, the Hulk is a bad-ass character, amirite?)

basically, i would like to see about making the most flexible AI script out there that can be tailored to be used for various different enemies.

thing is, what i’ve not wrapped my head around quite yet is wether i can make this flexible such that the creator can add in different AI states on the fly or if they should be hard-coded in there. not sure, that’s where my newb is showing.

so, first off, i would think that the code(pseudocode) would go something like this.

i’m still learning and now going through some pretty nice AI demos and tutorials as well as going over other AI scripts… but, do you have any tips or advice? any resources you would recommend that anyone interested in doing follow first?

okay… i’m breaking down the states that will be needed in a script… i’ll be needing to do some research to integrate some features but hopefully this will act as a guide to help allow.

ideally, if i can, i’d like to make behavior for this script like you’d get from a marine or other military enemy in the vein of Metal Gear Solid.

so, here’s the list (which i’ll be fleshing out as i go.)

if you think this is not comprehensive enough, please chip in what states you think are missing and how they should behave.

hmm, i’m looking through the documentation and it looks like it might not be possible to create a multidimensional array for this… being able to store values for the settings such that it would look like this.

that kinda thing (i know this array would not cover all the potential states or values, but i thought i’d put it down as an example. is my research incorrect and multidimensional arrays not possible to be declared by the programmer themselves?

if not being able to create multidimensional arrays, is it possible to nest separate arrays inside another “master” array? like this?

Whats The collaboration, gossip and learning sections of the forum for again? Hope i dont offend, but i see more clutter than butter in the scripting section.

Any One Else?

Zomg Multidim array of states?

Instead of researching them, you should be researching topics such as enumerated bitvectors, behavior trees and most importantly classes.

welp, on to the rest of the script…

so, a couple features that i think will be needed… first is a range variable. simple enough.

next is a form of “checker” to detect what is within range and what their ID is. it would not bode well to make an enemy lock on to another enemy and start attacking… well, unless the “confuse” spell was used… and in a case like that if there is a sort of “who is this?” check made, suppressing that could help make being “confused” work (or in some cases like a smoke bomb making it so they fire at whatever moves… or they’re “beserked.”)

i would gather that the tag system could be used for this… every cycle, check if there’s another character object within set range and check to cache what their tag is. if the tag is “player” lock on. if the tag is “enemy” cache for later things like idling or chatting animations (or again, in the case of “confuse” attacking as well.)

so, the code for that (as i understand) would be this.

the way i see this, it could be laggy since it’s checking ALL non scene objects in the level and calculating the distance. not sure how to get around this one… tips? (pseudocode is perfectly fine.) a cheat i think that could be used would be to create non-renderable objects to act as range… such as a sphere and a cone for range and visual IDing

next would be to detect (if not already aggro’d) if they’ve been attacked or if the player is within range of their attack field and set that player tagged object as the aggro target.

whoops… if this is in the wrong section, my apologies. thought it would be in scripting since it is primarily dealing with a potential script.

It does deal with scripting, sure, but it’s you’re not asking for how to resolve an issue, but rather, a collaborative effort to build a script.

Collab, imho, would be better.

Good luck Red :slight_smile:
-Rob