» First Person Shooter

» Overview

This examples has taken the Unity "3rd Person Shooter" demo as basis to create an (almost) full blown server authoritative first person shooter using SmartFoxServer 2X. Additionally it utilizes SmartFoxServer 2X's ability to mix TCP and UDP based messaging.

TCP is the most common protocol deployed on the Internet. It’s dominance is explained by the fact that TCP
performs error correction. When TCP is used, there is an assurance of delivery. This is accomplished through a number of characteristics including ordered data transfer, retransmission, flow control, and congestion control. During the delivery process, packet data may collide and be lost, however TCP ensures that all packet data is received by re-sending requests until the complete package is successfully delivered.

UDP as well, is commonly found on the Internet, however, UDP is not used to deliver critical information – it forgoes the data checking and flow control found in TCP. For this reason, UDP is significantly faster and more efficient, although, it cannot be relied on to reach it’s destination.

All critical game informations between the server and client are sent via TCP for reliable delivery. This could be shooting for example, or animation sync, damage messages, etc. On the other hand, sending updates to the players Transform - which is continuously sent to all clients - is utilizing UDP.

The game features a simple lobby and multiple games can run at the same time as individual arenas.

>> DOWNLOAD the source files <<

» Installation

» Running the example

In order to run the application follow these steps:

  1. make sure your SmartFoxServer 2X installation contains the BasicExamples Zone definition;
  2. copy the /deploy/extensions/folder to the server's /SFS2X/extensions/ folder;
  3. start SmartFoxServer 2X;
  4. enable the server's UDP listener if not already done;
  5. make sure the client run on the same machine as the server (the IP address can otherwise be configured as explained in this document via the source files);
  6. open the /deploy/client/FPS.html file in a browser.

» Source code setup

The complete project is contained in a Unity package. To access and build it please follow the following steps:

  1. create a empty new Unity project;
  2. in the Unity project tab, right click and select Import Package -> Custom Package...;
  3. browse to the package for this example in the /source folder.

All relevant C# code is in the Scripts folder and the SmartFoxServer 2X client API DLL is contained in the Plugins folder.

The game features a server-side Extension, as described in the walk-through. In order to access its code, create and setup a new project in your Java IDE of choice as described in the Writing a basic Extension document. Copy the content of the /source/server/src folder to your project's source folder.

» Walk-through

The First Person Shooter was developed by Full Control. You can download and read the developer's walk-through, which discusses the main SmartFoxServer 2X features implemented in the game and the techniques used to handle realtime user interaction.

>> READ the developer's walk-through <<

» More resources

You can learn more about the involved SFS2X features by consulting the following resources: