Looking for advice., Multiplayer system for a RTS game

Hello,

I’m currently working on a rts game, and i’m starting to look at the multiplayer part of it, what technology to use, etc.
Right now I can have over 100 units in the game, all shooting, so I will need to send at a minimum, 100 positions for the units, and then instantiate the shoot objects in both the client and the server.
I tested the Unity Network with a simple program, just moving 2 cubes with the keyboard, one controlable on the server and the other on the client , and I got it working, simply using a Network View in each cube, and the process of creating the cube was done with a RPC call.
So, this kind of works, it’s a bit laggy in a LAN, and i can imagine will be very laggy in a WAN.
I Serialized the transforms of the cubes, but this it’s still laggy, i guess i will need some kind of prediction.
Before going forward with this, I wanted to know if you guys think this is suitable for what i’m tryng to do. Can this system work in a rts game like the one i’m doing ?
What I like about this system is that I can have later a master server in php, to connect all clients, and I can run this master server in any webserver i wish.
I took a look at smartfox, but I will need a physical server to run the master server, besides it has restrictions on the number of people than can be connect, I may be wrong but i think smartfox is too big for what i’m tryng to do, I simply want 2 players connected, i’m not doing a MMO.
So…, with all this, I was looking for advices, on what tech would be suitable for what i’m tryng to do.

Any comments are really appreciated :slight_smile:
Thanks,
Bruno

I’m going to make an RTS one day too. And actually this is the reason I learned C# in the first place. I making an multiplayer pong-like game now and now I can say that if I’d started immediately with RTS I would have to rewrite it from scratch for multiplayer. Multiplayer game is very different from singleplayer. I would advice you to make some simple multiplayer game first and then rewrite your RTS.

Anyway. What to read on the subject: Networking for Game Programmers

or at least What every programmer needs to know about game networking

And you will probably be interested in article about Age of Empires Multiplayer

Those cubes were laggy because your Edit ProjectSettings Network Sendrate is 15, if you will make it 30 it will be smooth over lan. And it’s fine for two cubes. But it will be too much traffic for a 100 units. Sending whole transform is overkill, you need only position and rotation. Vector3 Scale for a 100 units 15 times per second is a lot of traffic. For bullets you need only position. How to send only those look up in M2H tutorial. NetworkRigidbody script.

stash, thanks for you input :slight_smile:
I’m doing exactly what you adviced, i’m doing a little side-project with cubes, to get the hang of things in Unity. It’s not the first time I implement networking in games, I did this many years ago using Raknet in C++, much harder than now tough, altough the same principles stand.
I did increase the sendrate to 45 and now it’s kind of smooth over Lan, however i suspect that even this simple thing will be slow over net.
Did you found Unity default networking slow ?

Thanks,
Bruno

Well, it’s my first experience with network game so I can’t tell whether it’s slow or not.
Increasing sendrate is not an answer for a real game. If you want a smooth movement you should update gameobject position in update or fixed update if it is a rigidbody. So you have class variables which you update every network tick (in OnSerializeNetworkView - look up NetworkRigidbody script). And based on those class variables you update your position in Update or FixedUpdate. And the movement will be as smooth as your frame rate.

you should looking at interpolation and extrapolation to keep the movement smooth with lag.

just a suggession… IMO sould help minimaze your traffic. If you have or can group units somehow for example in a squad. You just send the center position of the squad and calculate each unit position from that point. And of cource you need to add interpolation|extrapolation…

Thanks for the suggestions guys.
I’m thinking in doing something like this :
In a p2p connection,

client : sends to server the information that unitA will move to position B
server : receives the request, and orders unit to move to Position B, all updates moving etc will be computed in both client and server. I believe the result will be the same in both machines, because the pathing algorithm is pretty much deterministic.
I believe this might work, altough I will need to test it :slight_smile:

This topic is a bit old but if anyone looking to solve a similar issue the best solution I came up with is this one:

every time you click a ground your unit starts calculating the path to that position (im using Astar algorithm for path finding).
Right after/before calculating your path send the destination (mouse click) coordinates to other users as well (over buffered RPC call).

On RPC “listener” call the same function you use to calculate path for unit and make him move on path. This way every client will calculate the path for other client’s units himself. No need to sync the position every second. No lag at all.

Note: make sure the RPC call that sends destination point is within “if (networkView.isMine)” case so other clients wont send you back your own destination coordinates :slight_smile:

Example of script attached to unit:

function Update () {
if(networkView.isMine){ //only we can control our unit and send his destination over network
if( Input.GetMouseButton(0) ) { //on mouse click get the point on the ground
var hit : RaycastHit;
if( Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), hit, 100, groundLayer)) {

seeker.StartPath(transform.position, hit.point, PathFound); //get the path to the point on the ground

networkView.RPC(“SetPosition”, RPCMode.OthersBuffered, hit.point); //tell other clients we’re we moving at

}
}
}
/moving logic for units here after the path is calculated/
}

@RPC
function SetPosition(newPos : Vector3) {
if(!networkView.isMine) { //we’ve received a destination position from other player
seeker.StartPath(transform.position, newPos, PathFound); //get the path to the point on the ground, make sure movement logic launches once path is calculated
}
}

This wont work that easily if your game uses authoritative server model however (because path finding is done on server then).

Hint: in RPC listener check if unit has been created less than second ago and if so teleport him to his position immediately. This is to avoid calculating path for outdated buffered RPC calls (so when you join the game you wont see all other units running the paths they were running before you joined :slight_smile:

Take a look at uLink at www.muchdifferent.com
It’s the most awesome tech for doing multiplayer games which need unity based and physx based servers. To have things deterministic is another story which can be solved by specific math libraries.