Convert Figma logo to code with AI

Unity-Technologies logoFPSSample

A first person multiplayer shooter example project in Unity

4,850
1,832
4,850
105

Top Related Projects

Doom 3 BFG Edition

The 2013 edition of the Source SDK

88,735

Godot Engine – Multi-platform 2D and 3D game engine

Quick Overview

The Unity-Technologies/FPSSample is a comprehensive first-person shooter (FPS) game sample project developed by Unity Technologies. It demonstrates best practices for creating multiplayer FPS games using Unity, showcasing networking, game systems, and performance optimization techniques.

Pros

  • Provides a complete, production-quality FPS game sample
  • Demonstrates Unity's latest multiplayer networking solution
  • Includes advanced graphics and performance optimization techniques
  • Serves as an excellent learning resource for game developers

Cons

  • Large project size may be overwhelming for beginners
  • Requires a good understanding of Unity and C# programming
  • May not be suitable for small-scale or mobile game projects
  • Some components might be overkill for simpler FPS games

Code Examples

// Example of player movement in the FPSSample
public class PlayerMotor : MonoBehaviour
{
    public void Move(Vector3 movement)
    {
        m_CharacterController.Move(movement * Time.deltaTime);
    }

    public void Rotate(float rotation)
    {
        transform.Rotate(Vector3.up * rotation);
    }
}
// Example of weapon firing logic
public class WeaponSystem : NetworkBehaviour
{
    [ServerRpc]
    public void CmdFire()
    {
        if (m_NextTimeToFire > Time.time)
            return;

        m_NextTimeToFire = Time.time + 1f / m_FireRate;
        Fire();
    }

    [ClientRpc]
    void RpcOnFire()
    {
        // Play fire effects on all clients
    }
}
// Example of networked health system
public class HealthSystem : NetworkBehaviour
{
    [SyncVar(hook = nameof(OnHealthChanged))]
    private int m_CurrentHealth;

    public void TakeDamage(int damage)
    {
        if (!isServer)
            return;

        m_CurrentHealth -= damage;
        if (m_CurrentHealth <= 0)
            Die();
    }
}

Getting Started

  1. Clone the repository: git clone https://github.com/Unity-Technologies/FPSSample.git
  2. Open the project in Unity (recommended version: 2019.3 or later)
  3. Open the main scene: Assets/Scenes/Main.unity
  4. Press Play in the Unity Editor to run the game in single-player mode
  5. To test multiplayer, build the game and run multiple instances on the same network

Note: Make sure to check the project's README for any additional setup instructions or required Unity packages.

Competitor Comparisons

Doom 3 BFG Edition

Pros of DOOM-3-BFG

  • Full source code of a commercial-grade game engine
  • Mature and battle-tested codebase
  • Includes advanced graphics and audio features

Cons of DOOM-3-BFG

  • Older technology, not optimized for modern hardware
  • Less modular architecture compared to FPSSample
  • Steeper learning curve for newcomers

Code Comparison

DOOM-3-BFG (C++):

void idRenderWorldLocal::AddEntityDefs( int numNewDefs, idRenderEntityLocal **newDefs ) {
    for ( int i = 0 ; i < numNewDefs ; i++ ) {
        AddEntityDef( newDefs[i]->index, &newDefs[i]->parms );
    }
}

FPSSample (C#):

public void AddEntities(List<Entity> entities)
{
    foreach (var entity in entities)
    {
        AddEntity(entity);
    }
}

Both examples show methods for adding multiple entities to the game world, but DOOM-3-BFG uses C++ with lower-level memory management, while FPSSample uses C# with higher-level abstractions.

The 2013 edition of the Source SDK

Pros of source-sdk-2013

  • Provides access to the Source engine, a proven technology used in many popular games
  • Offers a comprehensive set of tools for level design, asset creation, and modding
  • Includes extensive documentation and community support

Cons of source-sdk-2013

  • Uses older technology, which may limit graphical capabilities compared to modern engines
  • Steeper learning curve for developers not familiar with C++ or the Source engine
  • Limited cross-platform support compared to Unity-based solutions

Code Comparison

source-sdk-2013 (C++):

void CBasePlayer::PreThink(void)
{
    if ( IsObserver() )
    {
        Observer_PreThink();
        return;
    }
    // ...
}

FPSSample (C#):

public override void OnUpdate()
{
    base.OnUpdate();
    if (IsLocalPlayer)
    {
        UpdateCamera();
    }
    // ...
}

The code snippets show differences in language and structure between the two projects. source-sdk-2013 uses C++ with a focus on specific game logic, while FPSSample utilizes C# within the Unity framework, emphasizing component-based architecture.

88,735

Godot Engine – Multi-platform 2D and 3D game engine

Pros of Godot

  • Open-source and free, allowing for full customization and community-driven development
  • Lighter weight and faster performance, especially for 2D games
  • Built-in scripting language (GDScript) designed specifically for game development

Cons of Godot

  • Smaller ecosystem and community compared to Unity
  • Less extensive documentation and learning resources
  • Fewer pre-made assets and plugins available in the marketplace

Code Comparison

FPSSample (C#):

public class PlayerController : MonoBehaviour
{
    public float moveSpeed = 5f;
    public float mouseSensitivity = 2f;
    private CharacterController controller;
}

Godot (GDScript):

extends KinematicBody

export var move_speed = 5.0
export var mouse_sensitivity = 0.05

onready var camera = $Camera

Both examples show basic player controller setup, but Godot's GDScript is more concise and tailored for game development. FPSSample uses Unity's MonoBehaviour, while Godot uses its own node system (KinematicBody). Godot's export keyword is similar to Unity's public variables for inspector exposure.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

FPS Sample

Update about the state of the project: This project is based on Unity 2018.3 and no longer being actively maintained. Feel free to continue to use it as a learning resource or simply for inspiration. As always, you should upgrade to latest version of Unity and packages if you intend to start a project.

Thanks for checking out this sample!

This is a fully functional, first person multiplayer shooter game made in Unity and with full source and assets. It was developed by a small team from Unity Technologies. Our goals are to test and showcase new features in Unity and to be of use for teams who can bootstrap on top of this, extract useful bits and tools or simply learn from and get inspired by what is in the project.

Visit our landing page for more high level information about the project. Or reach out in the forum.

The project is using a number of new technologies: We use the new HD Render Pipeline, meaning all content has been authored for HDRP. We are also using the new network transport layer as well as the Entity-Component System. In the case of ECS, we have primarily adopted the "ECS-pattern" and use it in hybrid mode with a lot of regular components. As more and more features of Unity become available in ECS-aware versions, we will migrate to them.

Status and prerequisites

Current status at a glance:

Unity version: 2018.3.8f1
Platforms    : Windows (client and server) and Linux (server only)

Getting the project

To get the project folder you need to clone the project. Note, that

IMPORTANT: This project uses Git Large Files Support (LFS). Downloading a zip file using the green button on Github will not work. You must clone the project with a version of git that has LFS. You can download Git LFS here: https://git-lfs.github.com/.

The project size is about 18GB (size of Assets folder). Your cloned repository will be almost double of that due to git state. If it is much smaller, you most likely did not have LFS when you cloned.

Getting the right version of Unity

Once you have cloned the repository, you should install the version of Unity that is listed above in the prerequisites section. Make sure you include windows standalone support in your installation (and Linux support if you want to build the Linux headless server).

Opening the project for the first time

The following guide should take you to the point where you can hit play in the editor and run around the levels and also build a standalone version of the game and use it to spin up a server and connect a few clients to it.

The first time you open the project you need patience! It takes a while to import all the assets.

NOTE: Due to a bug in Unity 2018.3, you have to take the following step right after the initial import: 1 Search for Firstperson_Projection in the Project search field. Select the 4 shaders, right click and reimport them. 2 If you have script compile errors related to entities, you need to remove and re-install the entities package.

One day soon we will remove this note and there will be cake.

Once the editor is ready, open the Project Tools Window by navigating to FPS Sample > Windows > Project tools.

It should look like this:

Keep this window docked as you will use it a lot. From here you can open the levels, build assetbundles and build standalone players. Because this is a multiplayer game you will need to work with standalone players a lot.

Trying out preview mode

From the Project Tools window click Open next to Level_00. Our levels are split into multiple scenes but using these buttons will ensure you open all the scenes that make up a level.

Once opened, try entering playmode in the editor. You should now be able to run around in the level. This is what we call 'preview mode'. Here you can move around and test your level, player traversal and weapons.

Building bundles and standalone

Leave playmode again and in the Project Tools window, verify that it says "Building for: StandaloneWindows64..." under the Game headline. If it does not, change your platform in the usual way, using File > Build settings window.

Now, in the Project Tools window in the bundles section, press All [force].

This will build the levels and other assets into assetbundles. The first time around this will take a significant amount of time as all shaders have to be compiled.

Once you have built the bundles, hit Build game in the game section. This builds the standalone player. Again, first time will be slow.

NOTE: Due to a limitation in Unity 2018.3, you have to look out for errors like this Maximum number (256) of shader keywords exceeded, keyword <KEYWORD_NAME> will be ignored. and similar. If you get these, you can close and open Unity and then try and build again. The errors are relatively harmless but can lead to graphical artifacts as some shaders will have wrong keywords.

Using the quick start launcher

When this is done, locate the "Quick start" section at the bottom of the Project Tools window. Fill out the settings like this:

Mode: Multiplayer
Level: Level_00
Clients: 1
Headless: Checked
Use editor: Unused

Now hit the green Start button. This should launch two processes: one is a standalone, headless server, the other is a client that will attempt to connect to the server.

Congratulations! If you made it this far you should celebrate a bit!

Development of FPS Sample, Contributions etc.

As of today, internally development of the project happens on Perforce. We push versions of the project to github from there. As we do that we will update the CHANGELOG with highlights but the full history is not carried over.

For practical reasons we are not able to take larger contributions just now. But bugfixes are very welcome! Read the guidelines for contributing in CONTRIBUTING.

More information

Check out the Documentation folder for more information. In particular, the Getting Started Guide is a good place to, well, start.

License

Our intention is that you can use everything in this project as a starting point or as bits and pieces in your own Unity games. For the legal words, see LICENSE.md.