irrAI 0.50 - AI module for Irrlicht [Updated 28/11/09]
For fleeing it's not necessarily good to just run in the opposite direction as that provides the player with a direct line of sight with the NPC, i.e. they just shoot straight in front of them and hit the NPC.
Best thing to do is to try and run off to the side so it's a moving target so harder to shoot at.
I had trouble with my fleeing methods in my Uni project, basically because the best working implementation i managed to get done in the available time was to just pick a random waypoint in the environment, plot a path there and follow it. But sometimes that would make the NPC run into the player which is obviously not a good fleeing plan!
Best thing to do is to try and run off to the side so it's a moving target so harder to shoot at.
I had trouble with my fleeing methods in my Uni project, basically because the best working implementation i managed to get done in the available time was to just pick a random waypoint in the environment, plot a path there and follow it. But sometimes that would make the NPC run into the player which is obviously not a good fleeing plan!
what about giving the nodes an flee and cover value? so if the player is near NPC's. NPCs will use the best cover nodes (for example high cover value) to walk over and the same for fleeing, they use the best cover and fasted routes to other fleepoints.
than you can precalculate different paths and get the best value for that state/second instead only the lowest path node count
than you can precalculate different paths and get the best value for that state/second instead only the lowest path node count
Compete or join in irrlichts monthly screenshot competition!
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
Blog/site: http://rex.4vandorp.eu
Company: http://www.islandworks.eu/, InCourse
Twitter: @strong99
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Ok. Have another idea for this.For fleeing it's not necessarily good to just run in the opposite direction as that provides the player with a direct line of sight with the NPC, i.e. they just shoot straight in front of them and hit the NPC.
1. Check the opposite direction (180 or less degre angle) with ray intersection where the NPC would find cover (wall that will protect the NPC). With the same ray intersection test, find a suitable position for the NPC then this will be the DESTINATION waypoint. You could determine the directional vector from the position of the NPC and the attacking node.
2. While on the destination waypoint, check for the attacking node position and distance, if distance is too near (determine a value), re-plot the trajectory.
3. If the NPC reach the destination, check the attacking node position and distance again then repeat the same until the NPC evade the attacking node. (Sufficient distance from the attaking node and NPC)
4. If the distance from the attacking node from the NPC is far enough, find the nearest static waypoint to patrol and go there (checking again not to go thru the walls)
Ok, well there were some concerns over performance when handling a fair number of NPCs in a scene. Christian mentioned wanting around 20 NPCs in a level at one time.
I just tried out adding 20 simple NPCs (checking their FOVs and plotting paths all over the place) into my test scene (of 8 waypoints) and the framerate didn't drop below 60 at any point with vsync on. Without vsync it was up at a steady 125, hopefully with some optimisations that can be boosted somewhat, but it's not a bad result i feel for now!
It's around 40 NPCs, on my system, that the framerate starts having problems, then it moves around between 50 and 60 fps (vsync on).
Now 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.
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 us a shout!
Anyway, onto the code. What i've done is made an FPS example project which shows how you might go about using the library for a FPS sort of AI (based on the previous demos i've shown). There are 2 NPCs which 'patrol' around randomly and can detect each other in their FOVs (they don't actually do anything except put a list up of what's visible to them in the GUI). If you think there's only one NPC wandering round then it's probably because they're on exactly the same path, having started from the same waypoint, eventually they'll split off!
Right, well.. no idea how to upload to my sourceforge project (if anyone can tell me how that'd be great!)
So here's the source release:
MediaMax (i'll try to mirror it elsewhere tomorrow)
Any problems or feedback then let me know!
I just tried out adding 20 simple NPCs (checking their FOVs and plotting paths all over the place) into my test scene (of 8 waypoints) and the framerate didn't drop below 60 at any point with vsync on. Without vsync it was up at a steady 125, hopefully with some optimisations that can be boosted somewhat, but it's not a bad result i feel for now!
It's around 40 NPCs, on my system, that the framerate starts having problems, then it moves around between 50 and 60 fps (vsync on).
Now 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.
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 us a shout!
Anyway, onto the code. What i've done is made an FPS example project which shows how you might go about using the library for a FPS sort of AI (based on the previous demos i've shown). There are 2 NPCs which 'patrol' around randomly and can detect each other in their FOVs (they don't actually do anything except put a list up of what's visible to them in the GUI). If you think there's only one NPC wandering round then it's probably because they're on exactly the same path, having started from the same waypoint, eventually they'll split off!
Right, well.. no idea how to upload to my sourceforge project (if anyone can tell me how that'd be great!)
So here's the source release:
MediaMax (i'll try to mirror it elsewhere tomorrow)
Any problems or feedback then let me know!
sourceforge upload:
ftp it up to: ftp://upload.sourceforge.net/incoming/
then go to admin->files i think to create a release version.
ftp it up to: ftp://upload.sourceforge.net/incoming/
then go to admin->files i think to create a release version.
That's so uber-lame... Wish they had a browser upload option!
I guess i'll have to get some ftp software installed then.. Any suggestions?
Incidentally i'll continue to improve the FPS example and i also have an RPG example in the works and am considering other types of examples too, any suggestions are welcome!
I guess i'll have to get some ftp software installed then.. Any suggestions?
Incidentally i'll continue to improve the FPS example and i also have an RPG example in the works and am considering other types of examples too, any suggestions are welcome!
Last edited by JP on Wed Jan 16, 2008 9:02 am, edited 1 time in total.
-
- Posts: 914
- Joined: Fri Aug 03, 2007 12:43 pm
- Location: South Africa
- Contact:
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Just open the FTP url in windows explorer (you can add it as a network resource in your network neighborhood too). Either just include login and password in the url or login using right click menu once the folder is opened.JP wrote:That's so uber-lame... Wish they had a browser upload option!
I guess i'll have to get some ftp software installed then.. Any suggestions?
Try "ftp://username:password@ftpserver.com/p ... somewhere/". (Explorer needs outgoing network access to port 21 for this to work).
If it still doesn't work, try a public ftp server like "ftp://ftp.microsoft.com/". It should work - if it doesn't there is something blocking your traffic (software, firewall, etc.). If it works the problem might be the ftp server or the data you provided.
----------
Just had a quick look on the header files:
Instead of setting the enemies for each node, would be nice having some simple faction system.
So instead of setting the enemies for each NPC (could be quite some work too ), create factions like "team red" and "team blue" or "team 1" and "team 2" or whatever and then add NPCs to them (constructor parameter, get/set method, etc. in NPC). Maybe in addition add one or to default factions "hostile to everyone" and "hostile to noone" to allow simple implementations for FFA etc. where you'd need one faction per NPC.
----------
Some additional thoughts:
Supporting up to 256 factions:
One char/byte member variable on each NPC and a 256x256 matrix in the AI manager holding the alignments/reputation where a 0 would be "kill on sight" and 255 would be "superbest ally". In addition there might be some way to override those defaults later on.
The AI manager could also use an array of 256 <NPC> lists to keep track of NPCs in various groups and allow faster selection.
If it still doesn't work, try a public ftp server like "ftp://ftp.microsoft.com/". It should work - if it doesn't there is something blocking your traffic (software, firewall, etc.). If it works the problem might be the ftp server or the data you provided.
----------
Just had a quick look on the header files:
Instead of setting the enemies for each node, would be nice having some simple faction system.
So instead of setting the enemies for each NPC (could be quite some work too ), create factions like "team red" and "team blue" or "team 1" and "team 2" or whatever and then add NPCs to them (constructor parameter, get/set method, etc. in NPC). Maybe in addition add one or to default factions "hostile to everyone" and "hostile to noone" to allow simple implementations for FFA etc. where you'd need one faction per NPC.
----------
Some additional thoughts:
Supporting up to 256 factions:
One char/byte member variable on each NPC and a 256x256 matrix in the AI manager holding the alignments/reputation where a 0 would be "kill on sight" and 255 would be "superbest ally". In addition there might be some way to override those defaults later on.
The AI manager could also use an array of 256 <NPC> lists to keep track of NPCs in various groups and allow faster selection.
Last edited by Ico on Wed Jan 16, 2008 5:35 pm, edited 1 time in total.