SFS2X Docs / ExamplesUnity / fps
» First Person Shooter
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.
» Running the example
In order to run the application follow these steps:
- make sure your SmartFoxServer 2X installation contains the BasicExamples Zone definition;
- copy the /deploy/extensions/folder to the server's /SFS2X/extensions/ folder;
- start SmartFoxServer 2X;
- enable the server's UDP listener if not already done;
- 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);
- 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:
- create a empty new Unity project;
- in the Unity project tab, right click and select Import Package -> Custom Package...;
- 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.
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.
» More resources
You can learn more about the involved SFS2X features by consulting the following resources: