Multiplayer Game Design with Mirror: Managing player view

I new to Unity. This is more of a multiplayer game design question for unity using mirror. with a dedicated server. Consider a game where you have two cities and two players: player one in city A, and player two in city B. What is the best method to keep these players separated until one of them enters the other city, such as player one enters city B? Based on my experiments, when an object is spawned from the server it spawns for everyone and all players see it. So, if player A asset is spawned it is seen by player B though they are in separate locations and should not see each other. I hope this makes sense.

  1. Do I have different positions for each city within the game space? City A at 1000,1000,1000 and city B at -1000,-1000,-1000? Does that mean then that the entire game map is loaded on the server?

  2. Do I use scenes and mange that? That doesn’t seem to work.

  3. Do I use room managers and have two rooms? I haven’t figured that out yet so any tips there would be great.

  4. Any Other ideas?

I really appreciate it. Thanks!

A multiplayer game is a bad choice if you are new to Unity. I’d recommend doing a smaller single player project, master Unity, then take on your multiplayer project.

Though I’m not using Mirror in my multiplayer project, I have similar issues. Unity doesn’t have built in functionality for multiple entirely separate worldspaces and physics simulations. My solution was separate server instances for each location. Players move from server to server when they change locations. There’s other more hacky solutions mentioned in previous forum threads, such as stacking entirely separate areas of the map vertically either far enough apart so they are outside of the camera far clipping plane or leveraging layers so you can’t see the other locations.

1000 units is really not that far apart. Unity only really has trouble at even farther distances from origin related to float accuracy issues. If you were running City A and City B at the same time on the same server then you would load the entire map for both at the same time on the server. Though server side you don’t actually need to load as much. You don’t need textures, vegetation without colliders, sounds, etc. You really just need anything with colliders on the server. This can be tricky with Mirror, since Mirror is designed for fast development of server and client together running the same scene though.

What part isn’t working?

I don’t have any experience with rooms. You haven’t really mentioned what kind of game you want this to be, so hard to make recommendations. For example, you’d use a completely different design if you were making a large single world MMO than if your game was going to be a large number of separate instances for a small number of players. If you were running dedicated servers you’d take a different direction than if the server was going to be player hosted.

Thank you for your input. I think I came up with a solution that will work for me. The 1000,1000,1000 coordinates was just an example btw. I understand that.

Mirror can control objects from the server for all clients, spawn them, move them, handle physics, etc. This is a great way to handle combat, etc, to avoid cheaters. However, it poses an issue to a MMO style game like I mentioned. My solution, at the moment, is to allow the client to spawn and manage objects, such as player avatars, etc., where the server provides information, when not in combat. So, walking around I can see other players because the server says these players are in these positions every second for example. The client can’t do anything to these objects, they are just there like background objects. Then, for combat, switch scenes to a controlled space that will be much smaller, avoiding this problem and any issues with floating point inaccuracies. I can then take advantage of the room options available in mirror as well. Not sure about that yet.

As far as being new, I’ve done a few small projects. But I’ve been coding longer than most of you have probably been alive. I started in middle school in the early 80s. My first “app” was a test making program in basic for my science teacher. Now, I partially own a software company and am responsible for over 800,000 LOC in a web app, and I’ve written over half of it, and I’ve learned over 40 programming languages over the years. This is just # 41 and the task is not daunting to me. I’m just doing this for fun.

Again, thanks for the input!
Cheers.

Since you already have coding experience, I would suggest developing your own custom UDP solution using sockets instead of trying to use an existing network library. That will give you the most flexibility and control. This is especially true for large games like an MMO.

If you build a custom network library for your game, you could also implement some client to client networking using STUN. You could use client-server for some networking and client-client for other networking. This way you could scale your MMO easily. For example, a main server might track each player’s location, and then automatically create client-client STUN groups for players near each other. Then those client side STUN networks would transports much more detail about players, but only send that information to nearby players instead of all players.

You can also use the low level library provided by Valve, they have reliable UDP and similar already made for you. It does not require steam

We use the same library but the one in steam, down the road we will migrate to this library so we can publish for other platforms than steam.

https://github.com/ValveSoftware/GameNetworkingSockets

I appreciate your suggestions. I did consider writing my own UDP but I don’t really want to reinvent the wheel. Mirror is free and was mentioned in a lot of posts and videos, so it was my first go to solution. @ thanks for that tip. I will look into it. That is an interesting concept.

Again, thanks for the input.

If you want to build an MMO, then you probably want to build your own custom networking solution that is perfect for the exact needs of your game instead of using an off the shelf solution. There has obviously been some testing with Mirror in MMO style games, but every MMO game has some unique challenges.