![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/iconlarge.png)
If you've been following christianclavet's First King project then you'll know that he's planning some big things for the irrlicht community in reusable modules. I decided to help him out with the AI for his project and what we want to do is to make an external module of AI functions that will be reusable in any irrlicht project.
Website & Downloads
irrAI Webpage
IrrAI Forum
IrrAI SDK 0.50: 12mb
- Download (for Irrlicht 1.4.2)
- Download (for Irrlicht 1.5)
- Download (for Irrlicht 1.6)
IrrAI Editor
Initially i was working on using IrrEdit as the editor to create and link together waypoints but i discovered fairly quickly that this wasn't a very viable option so i've now created my own editor which does the job a lot better.
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/neweditor.jpg)
There's a file called config.xml in the Media folder which allows you to change the video driver and screen resolution for the editor.
Please do try it out and let me know your thoughts!
Custom Entity Example
This example shows how I've opened up the IAIEntity interface so that you can really easily make your own entities if the basic implementations provided are not suitable enough for your needs!
Basically there's a very simple Turret entity which has been implemented which when you get in its field of view it will start shooting at you (if you're in range). The example also shows how the new AI sensors can be used for things like checkpoints and powerups.
Apologies for the poor screenie... I'm being shot by 'plasma balls'
![Laughing :lol:](./images/smilies/icon_lol.gif)
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/turretexample.jpg)
Calm-a-geddon Example
This example shows how you might go about using the library for pretty much a GTA sort of AI, what you'll see when you run the example is this:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/calm.jpg)
There are 2 types of NPC; zombies and cars. They can be considered as opposing teams and they have their own set of waypoints which are not linked together (but do cross over each other). The cars drive around on the roads with the usual rules of driving on the left by using one-way waypoint links. The zombies walk around on the pavements and zebra crossings by using two-way waypoint links. For your convenience the waypoints and their links are also colour coded to easily show the seperate groups.
When an NPC (of either type) sees another NPC they will stop dead. The cars will wait for the zombies to finish crossing the road and then continue and the zombies will do the same for the cars. If a zombie sees another zombie then they will stop for 4 seconds before moving past the other zombie. Currently they generally end up moving through each other which is less than desirable but evasion will come at a later date. Now as far as i can tell the NPCs will never get into a stalemate where they never move again and everything comes to a halt so let me know if you see this. There is one case where this will happen and that's if two cars start the simulation facing each other. This will make them never move and will cause a massive traffic jam eventually causing everyone to stop moving. If this happens just restart the app and if this initial stalemate doesn't occur everything should be fine!
FPS Example
This example shows how you might go about using the library for an FPS sort of AI, what you'll see when you run the example is this:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/newfps.jpg)
EXTRA STUFF: I've now extended this example so that you can take an active role and join either of the available teams, try it out
![Wink ;)](./images/smilies/icon_wink.gif)
There are 2 types of NPC. One chases and the other flees. The ones that chase, the guys in red, just randomly wander around until they sees the other enemy NPCs, the guys in blue. When they see the enemies they move towards them until they're in range to fire and then stop and start firing. The blue guys on the other hand don't have a weapon so would rather stay put and just scan the surrounding area, trying to make sure no one creeps up on them and when they see the red guys they just run away, crouched down, basically just to show you they're trying to get away. Unfortunately i haven't put any effort into the actual path they use to flee so they just plot a path to a random waypoint for now. When an NPC, in this example, is chasing/fleeing they have red exclamation marks above their head to show that they're, shall we say... 'aroused'... (stop that sniggering at the back!). That's about it for now, it's still very limited behaviour, but it's another step in the right direction!
Simple Example
This example simply shows you NPCs pathfinding. What you'll see when you run the example is this:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/newsimple.jpg)
There's only one type of NPC in this example, a 'patrolling' NPC who randomly wanders around between the waypoints.
RPG Example
This example shows how you might go about using the library for an RPG sort of AI, what you'll see when you run the example is this:
![Image](http://img.photobucket.com/albums/v232/SiliconMessiah/GameDev/newrpg.jpg)
There are 2 characters in the scene, one (Sydney) is controlled by you using the WASD keys and a 3RD person camera (very simplistic implementation as the focus of the example is not on this but on the AI) and the other (Faerie) is an NPC with which you can have a conversation. Go up to Faerie and press space, once the conversation is over follow her, simple as that. It doesn't really show off irrAI in any different way to the FPS example but it just shows how it can be used for different types of games and is just meant as a bit of fun (no disrespect to Niko at all
![Wink ;)](./images/smilies/icon_wink.gif)
Performance & The Code
As for the number of NPCs you can have running around at one time the current fps example can handle 30 quite easily, without dropping below 60fps (vsync on) and only really starts to struggle when you add up to 40 when the frame rate drops down to between 50 and 60fps.
This is still very early work, i can only have worked on it for a small number of hours i'm sure... So there's still lots to sort out and the source isn't perfectly seperated out into things that should be in the library and things that should be in the application. No doubt there will be many API breaking changes to come
![Wink ;)](./images/smilies/icon_wink.gif)
I've tried to comment the code as well as possible and it should explain how everything's done but if there's anything you're unsure of then give me a shout!
The future
Upcoming examples include examples of how to make unconventional AI things like automatic doors with the library and expansions to the chasing, fleeing and attacking behaviour. Nav mesh support is also hopefully something I can bring to IrrAI, this will greatly improve the pathfinding over the current waypoint graphs.