Jump to content
  • Advertisement
Sign in to follow this  
jeffkingdev

AI in multiplayer

This topic is 2190 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to know generally, how do ppl handle AI states on two clients connected to the server?

1) Does the server run the AI and send data to the clients?
2) Does the clients run some AI and the other client runs the other AI and sends that data to the server?
3) Position + Velocity isn't good enough, what is generally sent? For example, if I have a character who jumps, I need to know the position, velocity and maybe the state it's in... AND I also need to know what animation to play (or where in the animation to play).

I'm worried about #3 the most. Let's say you have a bunch of 3d AI characters running around a room in a 2 player game. The AI characters have a ton of states, how do you keep them in sync between the clients? I can't think of how you would do that. If the AI decides to jump, the client games need to go into the right states. Is it merely I send a current state to the client and if it changes, I run the new state logic?

Thanks
Jeff.

Share this post


Link to post
Share on other sites
Advertisement
It depends a great deal on the game.

Some details need to be kept in sync, other details do not, and those details are unique to every game.

It is generally best for clients to send events across the wire, not processed data. Let the server/host do the work to figure out authoritiatve data, then have the server send out (event + data) updates as needed.

Share this post


Link to post
Share on other sites
Hi frob,

It's for a sports related game. So, the players have a great deal of AI that goes on. However, I'm worried their state won't reflect and things will get out of wack easily.

What events vs processed data are you referring to? Like position data should not be sent? I'm trying to get a very basic sense on what's suppose to happen.

Example (Basketball game):
- PlayerA vs PlayerB
- PlayerA moves his guy to shoot the ball. The defender comes, jumps up and blocks his shot.
- PlayerB is moving around the court as well.

Server:
- What data is the server getting from playerA & playerB?
- Who is processing the AI for the non-user controlled characters?
- What data is sent the clients to show progress?

Thanks
Jeff.

Share this post


Link to post
Share on other sites
If you're lock-step networking, then the AI makes the same decisions on all the machines.

If you're client/server, then you likely run the AI on the server, and send the outcomes to each client, as some sequence of events or control data for the AI entities.
This could be anything from a high-level plan ("go over there and perform that action") to per-step instructions similar to what you'd send for a player in an FPS.
Edited by hplus0603

Share this post


Link to post
Share on other sites
for a 2-player only game... what makes more sense? Are games typically "lock-step"?

I would think because sports games are deterministic because of re-plays, that you would just have the server feed up the non-deterministic values (all the random numbers + input)?

Any ideas?

Share this post


Link to post
Share on other sites
Are games typically "lock-step"?
[/quote]

There is no "typical" implementation for games, although certain styles of gameplay (RTS, FPS, Racing, MMO, board games, etc) typically tend towards certain solutions or parameter combinations that best match that particular game style.

For example:
Almost all (big) RTS-es are lockstep.
Not many (big) FPS-es are lockstep.
Edited by hplus0603

Share this post


Link to post
Share on other sites
So what type of data will I be sending?

If I do a peer to peer 'lock-step' what would I need to send? for instance, do I need to send what frame of the animation their player is at? What about the AI, how can I be sure all the AI animations to be in sync? I can easily sync the player positions and velocities, but getting the animations to appear in sync, I'm not sure.

This is relatively important, for the case of shooting, you want to see the other player jump and shoot at about the right time.

Thanks
Jeff.

Share this post


Link to post
Share on other sites
do I need to send what frame of the animation their player is at?[/quote]

You need to send no other data than the player inputs for each step, if you correctly implement lockstep networking.

Share this post


Link to post
Share on other sites
hplus,

I guess I don't understand lockstep.

Are you saying every frame of the game you will need to:

* Receive Data from Host Peer
* Update the game
* Render the game
* Send Inputs from this Peer to Host

Host peer would look like:

* Receive Data from Client Peer
* Update the game
* Render the game
* Send Inputs from this Peer to Client

??

In a peer to peer method, is there a such thing as a host vs client?

I guess the host would be one in charge of gathering up the random numbers for the game and sending it to the client... is that correct?

So really the host is sending it's input data + random number generated data for this frame?? So that the client can generate the same AI, etc.? What about frame rate, elapsed time issues?

Sorry about these questions, I know very little about network programming.

Thanks
Jeff.

Share this post


Link to post
Share on other sites

I guess I don't understand lockstep.


I highly recommend reading the Age of Empires ("1,500 archers") article, linked to by the FAQ of this forum.


In a peer to peer method, is there a such thing as a host vs client?
[/quote]

You can use a peer-to-peer physical network connection, and still use a client/server logical game topology.

I guess the host would be one in charge of gathering up the random numbers for the game and sending it to the client... is that correct?
[/quote]

No. In a lock-step simulation, you initialize all the (pseudo-)random number generators to the same value once. Then, because all nodes run exactly the same commands in exactly the same order, the random number generators will generate the same values on all the nodes.

A simple way to think about this is that the game client looks something like:


game_step = 1;
for (step = game_step; step <= game_step + latency; ++step) {
send_empty_data_for_step(step);
}
forever() {
receive_packets();
if (i_have_all_packets_for_step(game_step)) {
step_simulation_once();
game_step += 1;
send_user_input_for_step(game_step + latency);
}
collect_input_commands();
animate();
render();
}


It's important that local commands do not actually have any effect on the local game state -- the local game state is only affected within step_simulation_once().

The "hosting" player still runs this kind of client, just like anyone else. Additionally, on the host, there is another logical process, that does:


game_step = 1;
forever() {
if (i_have_all_player_data_for_step(game_step)) {
send_all_player_data_for_step_to_all_players(game_step);
game_step += 1;
}
}


This can be interwoven in the main loop, or it can be a separate thread, or it can even be a separate process. It doesn't matter much. Note that the server doesn't necessarily have to simulate anything at all -- if you do proper lock-step, then the clients will all simulate exactly the same thing for the same step number. De-synch will be the result of a code bug, or the result of deliberate cheating. Edited by hplus0603

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!