About Store Forum Documentation Contact



Post Reply 
Question about NPC management
Author Message
jagatai Offline
Member

Post: #1
Question about NPC management
Greetings!,

I have been trying to wrap my head around NPC management and would like to hear what others have done or hear about best practices: (just looking for general high level overview)

1. Do most of you broadcast NPC position from server to clients or do you sent the destination from the server to clients and let clients *move* the npc instead?

1a. If your sending the destination from server to client and allowing client to *move* the NPC, how are you maintaining client/server synchronization regarding position, angle, fov etc... ?

1b. If your broadcasting NPC position from server to clients, do you find it consumes excessive bandwidth in large npc population areas? How do you throttle it down?

2. Do you create an external process which connects to server on a socket just to handle all NPC processing? or do you process everything from a single server application?

2a. Do you run your NPC controller in a single server application or do you have it externalized? i.e. external application communicating via socket to server application. (think headless client just for NPC's)

3. Do you guys do server side collision checks for the NPC then broadcast outcome to clients or do you handle collisions client side then broadcast back to server?

Im Just curious how some of you are handling NPC management in a client/server environment.

-J
07-10-2014 02:43 PM
Find all posts by this user Quote this message in a reply
SamNainocard Offline
Member

Post: #2
RE: Question about NPC management
1a. I use client to move NPC but server still periodically sent position, angle etc.., to let clients synced every once for awhile (every 1.0s or so).

2. I'm using single server. Although, Ragnarock Online (eAthena) is separate into 3 servers, one for login, characters and map (I think), connected to each others.

3. I use client side.

My game's network are P2P client side, so server are more like data center.
By allow clients to update specified NPC (who encounter NPC first will be the one who update those NPC.)
07-12-2014 09:00 PM
Find all posts by this user Quote this message in a reply
jagatai Offline
Member

Post: #3
RE: Question about NPC management
(07-12-2014 09:00 PM)SamNainocard Wrote:  1a. I use client to move NPC but server still periodically sent position, angle etc.., to let clients synced every once for awhile (every 1.0s or so).

2. I'm using single server. Although, Ragnarock Online (eAthena) is separate into 3 servers, one for login, characters and map (I think), connected to each others.

3. I use client side.

My game's network are P2P client side, so server are more like data center.
By allow clients to update specified NPC (who encounter NPC first will be the one who update those NPC.)

Thanks for the reply!, unfortunately this doesn't seem to be an active topic.
07-14-2014 07:57 PM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #4
RE: Question about NPC management
Quote:1. Do most of you broadcast NPC position from server to clients or do you sent the destination from the server to clients and let clients *move* the npc instead?
Client moves them.

Quote:1a. If your sending the destination from server to client and allowing client to *move* the NPC, how are you maintaining client/server synchronization regarding position, angle, fov etc... ?
The server, a server has NPC's just like a normal client, however this server does all the pathfinding.

Pathfinding is a set of linear interpolations, call them points. the server calculates arrival time for when each point, also take rotation into consideration as some NPCs might have different rotation speeds.

pseudo : timeOfArrival = unitDist / unitPerSecond + rotation / rotationspeed

Send this information off to the client and let the client move its units according the the pre-calculated points and it's arrival time-stamp.
Each other frame or so, check if it has yet arrived at the first point and check if the time-stamp has been passed, if so then you can either speed it up alot till it gets there or simply place it there manually. Keep in mind that if it has slowed down too much and haven't reached the point and it's 2 seconds passed the server time keep that number and place it on the linear interpolation between the next points according to arrival time / distance roughly.

Also each time an Attack or new Movement is sent you could send current position as-well and if they are different make the client set it to that position instantly.

Server sends both spawn and deletion when it comes to FoV. Also anytime you receive that a player has targeted and wants to attack or so, do check on the server to see that the distance between the player and npc is valid for the action.

*There's tons more of thoughts but it's too much to keep ontop of your head.

Quote:1b. If your broadcasting NPC position from server to clients, do you find it consumes excessive bandwidth in large npc population areas? How do you throttle it down?
Spatial Partitioning : Divide your whole world into sub areas (Already done by EE but might have to do it on your own if you do not want to load some specific world data onto a Server, this also applies to Pathfinding) <- There are solutions for these and I could provide with few solution ideas.

Only do some updates to NPC if there are any "Neighbor" objects in sight, meaning that do not update its position etc if there's no players in it's FoV, etc.

Spatial Partitioning means that you can divide it into X amount of sub areas which means that instead of looping through 100's of players you might be dealing with a loop of 5.

watch out for O(n^2). A Spatial Partitioning system should reduce the amount of them.

Quote:2. Do you create an external process which connects to server on a socket just to handle all NPC processing? or do you process everything from a single server application?

For now it's a standalone code meaning that nothing is seriously bound to another part of the Server, but yet only one server developed.

What this means is that when the day comes that the server is actually turning out being slow I could simply pass it onto a second server without massive amount of development time.

Keep performance killers on a separate thread if you can, see it as if you were to create an IOCP Server. Worker thread and so on. <-- Be careful about this so you do not slow it down instead of giving it speed.
07-17-2014 12:28 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jagatai Offline
Member

Post: #5
RE: Question about NPC management
@TBJokers,

Thank you very much for the insight it certainly helped me get a better understanding!

-J
07-18-2014 07:03 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #6
RE: Question about NPC management
Yeah, some key questions and some great feedback. I'm not coding a multiplayer game but it was an interesting read non the less.
07-18-2014 07:35 PM
Find all posts by this user Quote this message in a reply
KraaxLeNain Offline
Member

Post: #7
RE: Question about NPC management
(07-17-2014 12:28 AM)TBJokers Wrote:  Spatial Partitioning : Divide your whole world into sub areas (Already done by EE but might have to do it on your own if you do not want to load some specific world data onto a Server, this also applies to Pathfinding) <- There are solutions for these and I could provide with few solution ideas.

Hey,

Just catching on this : what did you do for pathfinding ? I intended to load only the world pathmesh and then handle only pathfinding search on the pathmesh (wich should deal all the static object normally) and adjust collision by just creating server basic "flat" world with only caps actor for collision test or find a way to manage them with no use of physics or whatsoever.

Did you handle it a similar way ?
07-30-2014 10:43 AM
Find all posts by this user Quote this message in a reply
TBJokers Offline
Member

Post: #8
RE: Question about NPC management
Loading world once excluding data that I do not need and then I can simply use the Esenthel Provided pathfinding. It's nice if you use NavMeshes as it'll create a really good basis for you, and depending on the game size you might come into issues, however I suggest that you start by loading the world and having dummies for the data you do not necessarily need such as Textures etc.

This way you can use his, however if you feel like it there are plenty of other ways but might not be as good when it comes to details, but faster sure?
08-01-2014 05:37 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply