   Updating units / npcs in real time games
  In a real time game, it would probably be impossible to update the ai of units ever frame, so what method is best to take? Update a few units every frame, update every unit every x number of frame or something else completly? whats your beliefs?Lep  
  It depends on how many units you are going to have and how complicated it is to process each unit.  For example, if you have a couple hundred units with very simple AI, you might be able to get away with processing them all every couple of frames.However, assuming you have either a lot of units, complicated AI, or both, there are several things you could do.  You could do as you say and just process some portion of the units every frame.Another option would be to process AI for units that are close to the player more often than far away units.  (This only works in certain circumstances however.  This obviously isn''t going to cut it in an RTS, but it could work in an RPG)Something else you might try is to do a ''minor'' AI update for each unit every frame and do a ''major'' update staggered every X frames.  By minor, I mean something like moving the unit along the path it was already traveling or performing other simple tasks.  Then, on a major update, you do complicated things like pathfinding and decision making.Hopefully, that will help you out a little, or at least spark some thoughts.  Do you have a specific game type in mind or is this more of a general question?  ;  Try updating a unit x number of frames were x is the distance in screens from the player. Ie units within a one screen radius of the player are updated each frame, those two screens away are updated every 2 frames, 3 screens = 3 frames, etc. If the screen can be moved away from the player, then update according to the view screen. If it is still to frequent, make x into x squared.;  Idea 1: Event-based updating: Only update when something significant happens. These could be things like "Player enters new tile", "Player appears in view", "Monster killed", "Door opens", etc. This way, you can pretty much guarantee that the higher-level thought processes are not being repeated wastefully, and are instead only being done when something interesting has happened that could change the situation.Idea 2: Do a few at a time: the simplest way, I find, could be to give all updatable objects a sequential ID number (also very useful for scripting, etc) when they are created. And each frame, you could perhaps update a fraction of these. For example, the first time you call UpdateAll()  (or whatever), it only calls Update() on objects where the ID number is 0, 10, 20, 30 (ID % 10 == 0), next time round, update where the ID number is 1, 11, 21 (ID % 10 == 1), etc etc, until it wraps around.Idea 3: Do as many as your CPU time allows: give yourself a given number of milliseconds each frame to process AI in. You might want to modify this dynamically to ensure the game runs at a smooth frame-rate. Basically, the idea is to have a pointer or iterator into the list of objects to update, and just call update on each one before moving onto the next, continuing this until you run out of time. Then, proceed to the next frame, and next time, continue updating where you left off last time. As you get more and more things to update, they will be updated less and less often, but the game should still play relatively smoothly.  ;  You could also put your NPCs into formations/groups and check whether the group wouild be active this round.ZoomBoyDeveloping a 2D RPG with skills, weapons, and adventure.  See my character editor, old Hex-Tile editor, diary, 3D Art resources at  Check out my web-site