1
\$\begingroup\$

I've been programming a multiplayer game and its coming together very nicely. It uses both TCP and UDP (UDP for movement and TCP for just about everything else). What I was wondering was how I would go about sending multiple moving AI without much lag. At first I used TCP for everything and it was very slow when people moved. I'm currently using a butchered version of this http://corvstudios.com/tutorials/udpMultiplayer.php for my movement system and I'm wondering what the best method of sending AI movements is. By movements I mean the AI chooses left/right/up/down and the player can see this happening.

Thanks.

\$\endgroup\$
2
  • \$\begingroup\$ Could you provide more details on how the movement is done? \$\endgroup\$
    – jcora
    Commented Jul 21, 2012 at 12:13
  • \$\begingroup\$ Also, it would be great if you actually described how you do it. \$\endgroup\$
    – jcora
    Commented Jul 21, 2012 at 12:15

2 Answers 2

1
\$\begingroup\$

I'm not sure what you mean by "multiple moving AI". Do you have several gameobjects that have AI, and they are moving in the same time?

If so, then here's how I'd do it.

You can have the same AI system on both the server and the client, for example, a state machine. Every gameobject with AI can be described by several states, like "walking_left speed". The AI system would provide various ways of changing these states, but that doesn't matter, because what you're interested in is synchronizing the movement between the server and the client.

What I did when I made my first multiplayer game, was foolishly have the server overwrite the positions of objects. Don't do this, because this results in choppy movement that is dependent on your network latency. Rather, you share those states, and make sure that both the server and the client know that a certain entity is walking at some direction (the direction vector can also specify the speed by its length). If everyone knows at which direction an entity is going, it's a simple matter of designing a movement system that make sure that in same time intervals, entities will be on the same position, and deploying that system on the server and the client side.

Someone at Valve made a post about making multiplayer systems: https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking.

Also, I believe that using both UDP and TCP is not exactly a good idea, I forgot why, so you might want to investigate... Another useful link: http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Thats what I mean. Thanks. I'll give this a go and let you know how it pans out. \$\endgroup\$
    – Malii
    Commented Jul 21, 2012 at 12:44
  • \$\begingroup\$ Great then, if I come up with something else, I'll edit the answer. \$\endgroup\$
    – jcora
    Commented Jul 21, 2012 at 12:49
  • \$\begingroup\$ Oh! That actually might explain why my TCP version of the movement lagged alot! I was sending the x and y of each player rather than sending booleans for their movement. I need to try this out. :D \$\endgroup\$
    – Malii
    Commented Jul 21, 2012 at 12:55
  • \$\begingroup\$ Yeah, I guess TCP just stacked a tonne of these and then sent them in a single packet... \$\endgroup\$
    – jcora
    Commented Jul 21, 2012 at 12:59
  • \$\begingroup\$ So this would be sort of like keyframes? Telling where each thing is, and what it should be doing, then both server/client track until next tic? What did @Smallbro mean aby "sending booleans for their movement"? \$\endgroup\$
    – Paul
    Commented Aug 20, 2012 at 20:08
1
\$\begingroup\$

I don't think that sending information about ai movement every frame is a good idea. What you should send instead is just player actions/commands (not positions). Basically what you need is a simulation (the same) running on every client and just synchronize player actions. If you use random number generators, just initialize them on the clients with the same seed.

This article could be also helpfull to you: http://www.gamasutra.com/view/feature/3094/1500_archers_on_a_288_network_.php?print=1

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .