Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
Could you provide more details on how the movement is done? –  jco Jul 21 '12 at 12:13
    
Also, it would be great if you actually described how you do it. –  jco Jul 21 '12 at 12:15

2 Answers 2

up vote 1 down vote accepted

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/.

share|improve this answer
1  
Thats what I mean. Thanks. I'll give this a go and let you know how it pans out. –  Smallbro Jul 21 '12 at 12:44
    
Great then, if I come up with something else, I'll edit the answer. –  jco Jul 21 '12 at 12:49
    
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 –  Smallbro Jul 21 '12 at 12:55
    
Yeah, I guess TCP just stacked a tonne of these and then sent them in a single packet... –  jco Jul 21 '12 at 12:59
    
If the movement is calculated client side, doesn't that open the game to hacking, i.e a hacker could change the speed stored in the client and fuck up the game? –  Click Upvote Aug 20 '12 at 13:42

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.