"Offline" multiplayer architecture question?

Hey everyone,
I am new to game development but have been a professional programmer for many years…

I am working on a game where players compete by creating a character with a combination of attributes, and then allowing them to compete against other players who have their own distinct combination of attributes.

When they compete there is no actual input or interaction from the players. It’s similar to clash of clans, in that competition can occur offline and the winner is predetermined by the players selected “build” if you will. Hopefully that makes sense.

If I could use unity’s collision management and physics it would make it much easier to develop, but I don’t want the outcome of the competition determined by the players client side device as it would be very easy to hack and just tell the server you won…

In an ideal world I would like to store the “build” of the players on the server, and then run the competition server side(ideally very fast, not in the speed the player would watch it), and the server would be the source of truth of who won, and then I would just be able to show replays by running it in the client side unity.

Is this feasible? Or do I need to write my own engine for simulating the collision/physics and then just output a format that I can pass into unity to render the replay?

If it’s feasible can I have a running unity server that I pass parameters into somehow and run a competition as fast as possible and then get a result out of the server that I can stick in database somehow? Can someone guide me on that?

Or is it not really feasible to architect it this way? I also have heard physics on unity isn’t deterministic so what my server calculates may be different than the client replay correct?

Hello CCB0x45,

Yes it’s feasible to make an accelerated simulation on the server, then replays it on the client at normal speed.
However as you mentionned, physic in unity isn’t deterministic, so you have to sacrifice a little bit of precision to do the synchronization correctly.

For the architecture question, I’m not sure to understand everything correctly, but it seems that you just need to send some data to the server, so it can process the simulation, then it will sending it back to you as a client.

I’m personnaly using Mirror for networking (GitHub - MirrorNetworking/Mirror: #1 Open Source Unity Networking Library), with this asset for smoothing things up (https://assetstore.unity.com/packages/tools/network/smooth-sync-96925),
and it works really well.

Cheers

Thanks, this is helpful. I had looked at Mirror. I am just wondering if Mirror is overkill for what I need. Isn’t mirror more for direct multiplayer, as in two people competing at the same time and giving input, getting output. In my case the clients may not even be active while the competition takes place… So there would be no client to communicate with really. I was hoping I could just do something simpler where the server “runs the simulation” of the two players, and gets a simple result out of it and sticks that in a database somewhere?

Hello,

yes it could be a bit overkill, but it also offers many advantages even for easy to use client/server communication system.
maybe what you can do is effectively runs a server that save data in some database and request that data from the client when/if needed, then runs it on the client at normal speed.
The only thing you should worry about, is to make sure my code would be playable easily with that data

Cheers

I don’t think OP would need smooth sync since that’s unrelated to the question. If I understood properly they are more interested in having the client and server play the same outcome.

Unfortunately if you are using physics the simulations very well could be different on server and client. I suspect if you keep it to raycast and don’t use rigidbodies for movement you might be okay though. Eg no velocities nor navmesh, manually move everything with maths.

Ultimately though, there is still a chance for error, although if you’re using my recommendation above I’d say the chances are pretty low.

I believe if you want absolute perfection and the most lightweight outcome possible you will just need to write your own or find a deterministic non-Unity based option.
If you do end up using a unity based networking solution though it’s worth your time to look at Fish-Networking instead. No other free option really comes close to it’s features and performance; this isn’t just marketing, it’s a fact. Plus, you can scene stack in FishNet letting you simulate each fight in a new scene with its own physics if you wanted. This would prevent raycast from hitting objects of other battles.

I’d be happy to discuss any other questions you have but I suspect you already know your answer.