Multiplayer networking newbie

Started by
22 comments, last by Hayer 13 years, 4 months ago
here is how I do it atm;

When the client presses the move-left-key it sends a byte to the server. The server then updates the position of the client and 1 / 30 sec it sends a update with the position to all the players.

I can now see that this wont work over the inet - as im only testing locally atm. So how does the pro's do this?

Im using Lidgren by the way..
Advertisement
First, what you do could work, although it may have a bit of lag.

Second, try the Forum FAQ, and especially the "zen of networked character physics" article by gaffer.
enum Bool { True, False, FileNotFound };
What kind of player count are you planing on handling? That kind of send player actions + lag compensation is typical of FPS games with 16 to 32 players.
Well, its a pretty simple game in logic-game code..

There is a team of 1-8 players on a map against some 8-10 different types of zombies.
And there will be a max of I guess 40-100 zombies.

The zombie limit is only limited by the net code - so I want some good net-code but I also want to keep it simple. So I guess I need to balance it between quality / simplicity.
You can have 10,000 zombies with close to zero impact on netcode. You do this by spawning the zombies according to known locations, and then simulating them using deterministic simulation on each machine separately. Because computers can be deterministic (assuming you have no bugs), they will simulate the same value on all machines.

Read the "1,500 archers" article about Age of Empires, linked from the Forum FAQ.
enum Bool { True, False, FileNotFound };
well, then pathfinding can't do anything "randomly" - so it seems kinda hard to make a smart AI?
You can use randomly generated numbers too, you just have to be careful not to let the pseudo-random state get out of sync. The Age of Empires game had some random movement in it, e.g. grazing animals. IIRC one of the bugs they had (from that article) was traced back to these animals not behaving deterministically, leading to a subtle but increasing divergence of state between peers.
You will want to look up Dead Reckoning. Basically, once you push left, you can assume that the left key is still being pushed until the client says that the key has been released.

By making such assumptions you can make the same calculations on the server. Further, you can simulate the same on all other clients as this is as much as they know.

Hope that helps you consider some different approaches.
Enoch DagorLead DeveloperDark Sky EntertainmentBeyond Protocol
The problem is that there is so many ways to do it!
I only want a simple way that still gives a good result compared to how hard/long time it takes me.

Okey; atm im testing this:

1. The user sends a byte when *he presses a key
2. the server starts moving the object and keeps moving it until it gets a "kill-button"-byte
3. the user lets go of the button and sends the "kill-button"-byte

As you see the server still does all the moving - so how would I add some prediction to this?
And does prediction have some math-formulas? I can't seem to find them.. Or maybe its just me that needs to skill up my google'r-brain
I am a newbie too but here is my 5 cents: you should always checking the ping time for all clients the server and keep them in a list.
Prediction comes right here, when server gets a button-press byte it assumes player has already gone pingtime*playerspeed and 'teleports' the player a little bit before making it move.
And same goes for clients if client gets a move-byte of another client it assumes player has already gone (mypingtime+hispingtime)*hisspeed and 'teleports' .
You can ofcourse have better approaches like sliding instead of teleporting.
I am currently trying to do some online zombie game too :). I'll just copy paste the ai code from server to clients and let them predict but once they get an update packet from server they will obey. And ill let clients delete bullets for example on collusion but i wont let them to decide damage or kill anything, at least in the beta.

This topic is closed to new replies.

Advertisement