3
\$\begingroup\$

I've built an online game with Unity with a very large open world. The server (which can be a local player, or run as a standalone application without a local player) simulates everything around players - so for example if there is an object or NPC at coordinates (100,34,20) but there aren't any players nearby then the object is not simulated. Objects are streamed dynamically from a database or generated procedurally depending on the object.

Problem

I want to enable players to go to other worlds. Of course it is impractical if not impossible to have global coordinates shared across all of these different worlds due to floating point limitations. I'll have to share the limited coordinate system for each simulated world.

The issue is the server would still need to render and handle physics of multiple worlds but could now potentially have conflicts with objects and/or people on one world appearing in other worlds. Essentially I need a way to divide up these "worlds" into parallel dimensions that are executed simultaneously on the same server (in one Unity scene).

Parallel Dimensions

A partial solution would be to have some sort of indicator, such as an integer (I'll call it "worldIndex") on each object to indicate which "world" that object exists in. This would work for clients since the server would be able to tell the clients only about objects that are on their world.

There would still be a problem on the server itself. Every world needs to be simulated in the same coordinate space. For a local player I could use the "worldIndex" to hide objects that aren't in the local player's current "world". But I still need to simulate physics for every world.

Unity's Layers could be used to mask physics interactions between objects. However I would then need to have at least one layer per world - and I already use multiple layers for various different interactions.

My thoughts are I would need something like a layer I could specify on each GameObject or some way to group a bunch of GameObjects together and instruct the physics system to only allow interactions within the group. But as far as I know no such mechanism exists within Unity.

Subspace Pockets

Another thought I've had is rather than using the Unity coordinate space directly, I could slice it up into "subspaces" or pockets. Each player would be in their own subspace, unless a player physically enters the same space that is already being simulated by another player, in which case that player would join the same subspace. But then I would have shift around the coordinate systems and it would increase complexity of merging players into and out of these subspaces. I would also have to generate subspaces dynamically as players enter new areas that are not currently being simulated.

Even if each world is extremely large, it is not necessary to use the entire Unity coordinate system around each player - a few thousand kilometers is more than enough.

Overall I think something along these lines is probably the best solution.

Multiple Servers

I could run one server per "world" and have a hand off process to make it transparent to players. But then I'd have to run multiple server instances and players would not be able to host their own server - at least not without a lot of additional overhead.

Question

So my question is: what is the best method for essentially running multiple, parallel simulations within a single Unity scene?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ It sounds like you are fighting with the engine in an extreme fashion to try to do this. Unity is simply not suited for this purpose. Running multiple server instances really would be the best way to handle the problem. Players running their own servers should be possible if you have a front-end which spools up the correct worlds as necessary. \$\endgroup\$
    – Ed Marty
    Jan 29, 2018 at 15:44

1 Answer 1

2
\$\begingroup\$

You want to look into two things:

  1. How to make portals in unity
  2. Non-Euclidean geometry in video games.

The mathematics is too much to go into here, but the basic idea for alternate dimensions is that you create a basis matrix which will allow a mapping of sorts between any point in the main game world, and any point in dimension x. So when someone translates between the real world, their position is transformed into the coordinate system of dimension x.

In order to allow translation, you need portals. Portals are artefacts, if you look at the game, Portal, which not only translate to other places, but also provide a view of that other place. That's done by some simple rendering tricks, but is outside the scope of this answer.

The portal itself is nothing more than a triggered event, which the script will get the new world, or dimensions basis matrix, transform the players current position, and then place the game entity into the world at the new location.

In such a way, you could have a world that is considerably smaller, or larger in dimensions than the real world, and use it for say, fast travel (like hyper space).

Non-Euclidean geometry is far too complex a subject to go into here, so on that subject I will simply say go read up on it.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .