Is there some tutorial about AI in Unity?I’ve searched but I can’t find anything.I wanna do some simple AI,something like search them enemy and attack him.The biggest problem is that I’ve no idea about how develop a search script.How can I do this?
GameObject,FindObjectsWithTag(“Player”) (finds the gameobjects in the scene with the tag player) and you place them in a list (if you have more than 1 player in the scene), then you order the list based on distance (Vector3.Distance). You get the closest one (first in the list), if distance from the player to the enemy (which has the script) is under the engage distance, you can do LookAt, move, fire anything you like. this is in open space, if you want him to follow a path to the target (player object) you need to implement a pathfinding system (A* pathfinding or smt similar)
The FPS tutorial on unity site has one example of it, and I’m sure the RPG one from bergzerg arcade does as well. If the behavior scripting concepts is what you’re looking for, you can also try this one:
http://forum.unity3d.com/threads/89543-Free-Simple-AI-Behavioral-script
There are also many algorithms (AI is nothing else than algorithms and state machines…) that can be found in specialized books, and even on internet.
Thank you guys!So I think that’s the hardest part of the game…
You might begin with writing your expected AI behaviour in meta-language, ie almost english phrases, and only when it is clear to you that your behaviour is fine, code it.
I also think that almost any algorithm you could find would be in meta-language, so get used to it