Unity multiplayer tutorial, physics calculations on server

Share

Creating the Server and the Client connection logic

This part of this Unity multiplayer tutorial with physics calculations on server will focus on the server and client logic, we will write two scripts attached to empty gameobjects to define the roles of the client and the server scene.

  1. Open the pongserver scene. In the scene, create an empty gameobject and name it Server.10-Unity-ulink-multiplayer-authoritative-physics-server-tutorial
  2.  In the Scripts folder create a new C# script named ServerLogic,  we will code the instantiation of the three prefabs on the server and on the client and manage the player’s spawn points.
    [snippet id=’116′]
    ServerLogic.cs – Unity multiplayer tutorial physics on server C# script code example download
  3. Add the ServerLogic script as a component to the Server game object in the pongserver scene.
  4. The Server game object needs another component to actually make the server starting, a uLink Simple Server script, add it to the Server from Component->uLink Utilities->Simple Server  and set its maximum connection option to 2. 11-Unity-ulink-multiplayer-authoritative-physics-server-tutorial

The code written in the ServerLogic script will handle player connection and instantiation. We will need to code the connection logic in the client to advance in this unity multiplayer tutorial.

  1. Open the pongclient scene, then create a new empty gameobject and name it Client.
  2. Add to it as a component the uLink Client GUI script, it will enable a mask that will let connect the client, you must click to connect to lacalhost once strated the server.
  3. Save the scene and the project, we successfully implemented player rackets log on and motion. If you build one .exe with the server scene and one exe with the client scene only you can test the logon and the motion implementation, you should see the racket on the client moving a little late respect to the server, this i wanted to take care of latency issues.12-Unity-ulink-multiplayer-authoritative-physics-server-tutorial

Next step in this Unity multiplayer tutorial with physics calculated on the authoritative server will be covering the ball implementation, we need a ball to score a goal in pong !!

Leave a Comment