Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Server terrain representation

Discussion in 'Multiplayer' started by ghx, Feb 11, 2010.

  1. ghx

    ghx

    Joined:
    Feb 11, 2010
    Posts:
    1
    Hey guys,
    I am pretty impressed with the unity thing and new to game development itself. I am trying to compensate for that by reading a lot here and there, but there is one thing which keeps bugging me. Consider a Server/Client architecture using unity as a client, Project DarkStar as a server and the terrain created with the unity editor:
    How can the server represent the terrain to distinguish between walkable and non-walkable areas, collision and so on? I tried to investigate myself, but it seems that problem is either hardly documented or it's such a basic problem that it's not worth mentioning it.

    I already read some things about pathfinding, navMeshs and heightMaps which seemed close to what I was looking for, but not exactly. The main question would be "how can I distinguish a "player" can walk to a certain position or not?"

    I am looking forward to any help.

    Greetings
     
  2. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    167
    The simplest approach is to convert your terrain height data into a grid of world y-axis values. You can then have a secondary grid of boolean values to determine whether the grid square is walkable or not.

    Assuming you allow players to be semi-authoritative over their position and rotation, when the player sends position data to the server, the x and z values are resolved into a terrain square and the player's y value is compared to the terrain height value for that square.

    The server would allow for small differences in the y-values to accommodate things like jumping, and some logic to consider what happens if the player falls from a high point, but any major discrepancies would result in the server auto-correcting the client (snapping them to the terrain), or taking more severe action such as kicking or banning a player if it appears that they are using a hacked client (maybe allowing them to fly over terrain, etc.).

    This same check could consider walkable and non-walkable areas as well, and possibly also track player speed to ensure that it is within normal levels. It gets trickier if you are trying to catch players walking through walls or other such obstacles, unless the walls are think enough to occupy 1 or more grid squares. This presents obvious difficulties when the walls aren't parallel to the x or z axis. Another challenge is multiple level buildings, or things like tunnels or caves which go beneath the terrain.

    You can also consider implementing basic physics on the server side too - using something like ODE or PhysX, but be aware that this will have a greater performance hit on your server resources.