Server generated battle scene instead of client - Concept assistance please?

Hi Guys,

This is my first post, so i’m quite new and have spent the last few months playing around and getting to grips with all of unity’s structure.

I’m looking a making a Rts game that doesn’t require the client / user to be connected all the time which is fine as no client (p2p) networking or master server is required, all data is held within database and calculations are made dependent on information contained within database.

I understand how to go about creating a battle engine and scripting battles to take place with all units being npcs etc. My issue is created by simulating the battle engine or scene as neither player involved is required to be online at the point of simulation (due to traveling time which occurs in real time) and therefore would require the scene to be simulated preferably at my host server which can then be played back to the users at next log on, or streamed like a video as the simulation takes place.

Is this concept even possible, if so how would i go about it, the only logical solution would be to have a master server create a game room or scene in this case to begin at a set time and simulate the scene which is recorded then played back, with results from the simulation posting results back into the database.

Please could anyone point me in the right direction?

Regards Gilduck

Sure it’s possible. The question as to how is really broad and depends on lots of other things - what other kinds of interactions do you want to support, what kind of network code is required, that sort of thing.

Your server code doesn’t have to be done in Unity directly - there are networking kits and tools (I use Photon, for example, pretty happy with that one, but there are others that may suit you better) and your server code is handling clients coming and going, processing messages from them, and managing the database. When some client connects and sends a message like “I want this legion to move to Corinth and attack that army”, the simulation loop on the server would take care of that. The client might come back and send some other message to the server like “tell me what happened so far” and the server response might be “they are still walking” or it might be “the battle is over, you won” or it might be “no army was found at destination, your troops are idle”. If it’s the middle of the battle (assuming that also happens in real time) then the client might get back information pertaining to the playback you were mentioning. If you want to render that as a movie, that sounds to me like logic / work that would be done at a client. After all the server wouldn’t want to spend a lot of time rendering some movie that no one might ever see - it should worry about the data and the simulation, not the presentation.

I don’t know if that helps, but as I said the question was pretty broad.

The Random class provides a seed value. It’s not documented at all, but technically, as long as the seed value is the same, all the calls to the Random.value will be the same.

Let’s consider this script :

UnityEngine.Random.seed = 2;
float randomValue = Mathf.Floor(UnityEngine.Random.value * 10)

The first three calls must give you these results : 4, 0, 8 - that’s the value that this code and this particular seed has given me.

So, if your two players have the same seed value, any Random result will be the same, thus assuring you they’ll see the same thing, no matter how much calls to the Random class you do.

All you have to do is generate in PHP an int value, store it with your data, and transmit it to your players along the other data, and making it the seed value of the Random static class.

Hope this will help you :wink:

(I didn’t test with the Random.Range method though, but I don’t see why it wouldn’t act like the rest).