AI Manage
by Güvenç Şahin · in Torque Game Engine Advanced · 03/30/2009 (2:00 pm) · 12 replies
Hi,
İ am working on a single player game and for NPC’s i am using “AI Guard Unit” with lots of modifications. But like i said before it’s a single player game so i have to use much more ai units in a level than a multiplayer game. Using more than 20 ai’s in a level is not acceptable for performance in my example however i have to use hundreds of NPC’s in the whole level. Using 10-15 NPC’s on the screen simultaneously is enogh for me. I have to manage ai’s for max performance. In this point i have some few different ideas.
1. I can divide my map into octree’s and create each group of ai’s when the player enter their areas.
2. I can put 20 ai’s to the level and set their next respawn points after death to the next location on the map.
3. I can check the distance from player of each ai in the level and activate just close ones.
Does any one has any better idea or basic solution to solve this performance problem.
Thanks.
İ am working on a single player game and for NPC’s i am using “AI Guard Unit” with lots of modifications. But like i said before it’s a single player game so i have to use much more ai units in a level than a multiplayer game. Using more than 20 ai’s in a level is not acceptable for performance in my example however i have to use hundreds of NPC’s in the whole level. Using 10-15 NPC’s on the screen simultaneously is enogh for me. I have to manage ai’s for max performance. In this point i have some few different ideas.
1. I can divide my map into octree’s and create each group of ai’s when the player enter their areas.
2. I can put 20 ai’s to the level and set their next respawn points after death to the next location on the map.
3. I can check the distance from player of each ai in the level and activate just close ones.
Does any one has any better idea or basic solution to solve this performance problem.
Thanks.
#2
03/30/2009 (2:48 pm)
I am not sure is it an efficient way to calculating the distance of each NPC and then activate think cycle. For huge numbers of NPC's it can be a problem.
#3
03/30/2009 (3:21 pm)
No activating the think cycle, making the think cycle faster for ones within a certain radius of the player.
#4
Also, as I remember, the AI Guard is all script, so maybe changing the ontick process, make the schedules for targeting longer (see Randy's above post). It's those type of raycast, container raycasts that eat performance. So do dynamic threat lists though I'm not sure if AI Guard uses that, I know KillerKork does.
03/30/2009 (3:26 pm)
How about spawning AI with triggers? That way they only spawn when the player walks into a nearby trigger, and don't all spawn at once. No distance or raycast check required.Also, as I remember, the AI Guard is all script, so maybe changing the ontick process, make the schedules for targeting longer (see Randy's above post). It's those type of raycast, container raycasts that eat performance. So do dynamic threat lists though I'm not sure if AI Guard uses that, I know KillerKork does.
#5
Triggers would be good. Just have to be careful and not do them like Rainbow 6. I can go to a door in a level and slowly move forward until the NPCs spawn then kill them before they have a chance to "think" about where I am:)
An no, I don't play fair:)
KillerKork? OK, search feature activated...
03/30/2009 (3:31 pm)
@Steve,Triggers would be good. Just have to be careful and not do them like Rainbow 6. I can go to a door in a level and slowly move forward until the NPCs spawn then kill them before they have a chance to "think" about where I am:)
An no, I don't play fair:)
KillerKork? OK, search feature activated...
#6
Rewriting that as a C++ class should allow you to have hundreds in game, you may want to look an AIManager class that does all your thinking and only allow it to process so much per frame and then prioritising requests to think so less important or further away players get processed last... that way if you struggle for frame rate it's only the less important stuff that's lost
03/30/2009 (4:14 pm)
You should be able to get a lot more than 20 AIPlayers in game without an issue so I'd suggest looking at where your losing your performance, which I'm guessing as you mentioned you're using AIGuard is on the scripting and probably the "think" areas.Rewriting that as a C++ class should allow you to have hundreds in game, you may want to look an AIManager class that does all your thinking and only allow it to process so much per frame and then prioritising requests to think so less important or further away players get processed last... that way if you struggle for frame rate it's only the less important stuff that's lost
#7
03/31/2009 (4:27 am)
Thanks for advices. I guess i am going to try both of the solutions. First i am going to optimize the think process and than set the spawn process of NPC's connect to the trigger system. I hope this will gain me some performance :) Thanks again.
#8
so idealy what you need are ai spawn points spread out all over your level, and set to spawn an ai when the player is within a 500m radius of a spawn point, and when the player moves more than, say 1km from a spawned ai, said ai is removed from the scene. this way you can have way more active ai, within sight, that are quicker, and in reality, a really endless supply of ai characters.
03/31/2009 (6:51 am)
I must say, I have noticed that there is a performance hit, not from the rendering of the ai characters, but from the thinking. sure, when they are not onscreen they are not rendered, but they are all still thinking, so say you got 100 ai characters spread out over 10km2, maybe only 10 are onscreen at any one time, but they ALL think, taking up proccessing power, even those 5km away, that you may never even see in the game, but they are there, wondering around, thinking about this and that. theres your performance hit. now if you got freindly ai aswell, maybe you got battles going on 7km away between enemy and freindly ai, everyone thinking stratergy and where to hide and whatnot.so idealy what you need are ai spawn points spread out all over your level, and set to spawn an ai when the player is within a 500m radius of a spawn point, and when the player moves more than, say 1km from a spawned ai, said ai is removed from the scene. this way you can have way more active ai, within sight, that are quicker, and in reality, a really endless supply of ai characters.
#9
Really depends on gameplay I think. But I see or expect no performance hit and I need the AI players ready to go, not wait to spawn.
I plan to do things (well, more complicated tha this). First schedule the think to be low, maybe 3-5 seconds. Second assign that schedule a very low priority, so the NPC during this time is assigned the GOAL of DO NOTHING. No animation, no nothing. So they will not be running around aimlessly.(of course I will have some that move regardless, trains, plains....)
I really have not seen the AI bog my system down, generally the graphics dies before the AI does.
03/31/2009 (9:22 am)
@deepscratchReally depends on gameplay I think. But I see or expect no performance hit and I need the AI players ready to go, not wait to spawn.
I plan to do things (well, more complicated tha this). First schedule the think to be low, maybe 3-5 seconds. Second assign that schedule a very low priority, so the NPC during this time is assigned the GOAL of DO NOTHING. No animation, no nothing. So they will not be running around aimlessly.(of course I will have some that move regardless, trains, plains....)
I really have not seen the AI bog my system down, generally the graphics dies before the AI does.
#10
04/02/2009 (4:19 pm)
Thanks for advices, i set a trigger for spawning ai's by groups. By this way i can spawn ai's group by group in the level. But i guess i have to delete or kill ai's which can survive behind of the player in the map. I mean if the player is in the area of third ai players i have to kill ai group 1,2 for max performance. Do you know a way to kill or delete ai's.
#11
04/02/2009 (5:39 pm)
Check out the "suicide" function (it's listed as a hotkey in key bindings script. It sends a damage message to the player which kills him. You'd want to check if an AI was still alive/exists, then call damage on it.//Something like this, it's from memory so might not be accurate
isObject(%yourbot)
{
%yourbot.damage(9000);
}
Torque Owner Randy Hearn - Magnum
Default Studio Name
Would it not be easier to have the NPCs already in the level but set their think cycle higher until they are in the players view? Of affected by the game somehow?
I plan to have at least 40-50 NPCs or more in each level, but they will be there from the start, just not active until something in the game triggers the action (player in range, sound ect...).
Also, to gain more performance I plan on moving my scripts to code. Reading back through, it sounds like #3 on your list is close to what I had planned on doing.