Skip to content

mamadbah2/multiplayer-fps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

70 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Multiplayer FPS - Rust Game Engine

Rust Bevy Rapier3D Tokio

A modern multiplayer first-person shooter built from scratch with Rust and Bevy Engine

Features โ€ข Architecture โ€ข Getting Started โ€ข Tech Stack


๐Ÿ“‹ About The Project

Multiplayer FPS is a modern take on classic maze-based first-person shooters, inspired by Maze Wars. Built entirely in Rust using the Bevy game engine, this project demonstrates advanced game development concepts including real-time networking, 3D physics, and multiplayer synchronization.

๐ŸŽฏ Project Goals

  • โœ… Learn Rust Game Development: Master Rust's ownership system in a game context
  • โœ… Multiplayer Networking: Implement client-server architecture with UDP
  • โœ… 3D Physics: Integrate Rapier3D for realistic collisions and movement
  • โœ… Real-time Gameplay: Achieve 50+ FPS with low-latency networking
  • โœ… Modern Game Architecture: Use Bevy's ECS (Entity Component System)

โœจ Features

๐ŸŽฎ Core Gameplay

  • First-Person Shooter Mechanics:

    • Smooth camera control with mouse look
    • WASD movement with collision detection
    • Shooting system with bullet physics
    • Health system and player elimination
  • 3D Maze Navigation:

    • Procedurally generated or JSON-loaded mazes
    • Dynamic lighting system
    • Wall collisions with Rapier3D physics
    • Multiple spawn points for players

๐ŸŒ Multiplayer Features

  • UDP Networking:

    • Low-latency client-server architecture
    • Asynchronous networking with Tokio
    • 20 Hz update rate for smooth synchronization
    • Supports up to 10 concurrent players
  • Real-time Synchronization:

    • Player position and rotation updates
    • Enemy player rendering and tracking
    • Death state synchronization
    • Automatic game start when lobby is full

๐Ÿ“Š UI & Feedback

  • In-Game HUD:

    • Real-time FPS counter (green overlay)
    • Minimap with player position
    • Player information display
    • Connection status
  • Audio System:

    • Footstep sounds during movement
    • Shooting sound effects
    • Spatial audio (3D positioning)

๐ŸŽจ Graphics & Physics

  • Bevy Rendering:

    • 3D mesh rendering for players and environment
    • Dynamic lighting and shadows
    • Material system with color customization
    • Camera system with configurable sensitivity
  • Rapier3D Physics:

    • Rigid body dynamics
    • Collider detection (walls, bullets, players)
    • Gravity-free player movement
    • Locked rotation axes for FPS controls

๐Ÿ› ๏ธ Tech Stack

Core Technologies

Technology Version Purpose
Rust 1.70+ Primary language (98.8%)
Bevy 0.15.1 Game engine & ECS
Rapier3D 0.23.0 Physics engine
Tokio 1.x Async runtime

Key Dependencies

[dependencies]
bevy = "0.15.1"                  # Game engine
rapier3d = "0.23.0"             # Physics simulation
bevy_rapier3d = "0.28.0"        # Bevy-Rapier integration
tokio = { version = "1", features = ["full"] }  # Async networking
serde = "1.0.217"               # Serialization
bincode = "1.3.3"               # Binary encoding
serde_json = "1.0.137"          # JSON parsing
thiserror = "2.0.11"            # Error handling
lazy_static = "1.5.0"           # Static variables
bevy_dev_tools = "0.15.2"       # Development utilities

๐Ÿ—๏ธ Architecture

Project Structure

multiplayer-fps/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ bin/
โ”‚   โ”‚   โ”œโ”€โ”€ client.rs          # Client entry point
โ”‚   โ”‚   โ””โ”€โ”€ server.rs          # Server entry point
โ”‚   โ”œโ”€โ”€ client/                # Client-side code
โ”‚   โ”‚   โ”œโ”€โ”€ components/        # ECS Components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ player_component.rs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ enemy_component.rs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ camera_component.rs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bullet.rs
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ world_component.rs
โ”‚   โ”‚   โ”œโ”€โ”€ systems/           # ECS Systems
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ player/        # Player mechanics
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ setup_player.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ move_player.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ rotate_player.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ shooting.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ send_update_player.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ step.rs (audio)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ enemy/         # Enemy synchronization
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ setup_enemy.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ receiving_update_enemy.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ move_enemy.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ handle_animation_enemy.rs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ world/         # World generation
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ load_json_world.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ spawn_map.rs
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ models_world.rs
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ common/        # Shared systems
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ fps_display_system.rs
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ window_config_system.rs
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ light_system.rs
โ”‚   โ”‚   โ”œโ”€โ”€ plugins/           # Bevy Plugins
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ player_plugin.rs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ enemy_plugin.rs
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ world_plugin.rs
โ”‚   โ”‚   โ”œโ”€โ”€ resources/         # Bevy Resources
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ network_resource.rs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ player_resource.rs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ enemy_resource.rs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ world_resource.rs
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ animation_resource.rs
โ”‚   โ”‚   โ””โ”€โ”€ udp.rs             # Client networking
โ”‚   โ”œโ”€โ”€ server/                # Server-side code
โ”‚   โ”‚   โ”œโ”€โ”€ udp.rs             # Server networking
โ”‚   โ”‚   โ””โ”€โ”€ utils/             # Server utilities
โ”‚   โ”‚       โ””โ”€โ”€ exception.rs
โ”‚   โ”œโ”€โ”€ common/                # Shared code
โ”‚   โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ protocol.rs    # Network protocol
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ game_state.rs
โ”‚   โ”‚   โ””โ”€โ”€ utils/
โ”‚   โ”‚       โ””โ”€โ”€ socket_utils.rs
โ”‚   โ””โ”€โ”€ lib.rs                 # Library root
โ”œโ”€โ”€ assets/                    # Game assets
โ”‚   โ”œโ”€โ”€ sounds/
โ”‚   โ”‚   โ”œโ”€โ”€ running.ogg
โ”‚   โ”‚   โ””โ”€โ”€ shoot.ogg
โ”‚   โ””โ”€โ”€ models/
โ”œโ”€โ”€ Cargo.toml                 # Project dependencies
โ””โ”€โ”€ README.md

ECS Architecture (Bevy)

Components - Data containers:

  • Player, Enemy, Bullet, Camera, Wall

Systems - Logic functions:

  • Movement, Rotation, Shooting, Collision, Networking

Resources - Global state:

  • NetworkResource, PlayerResource, EnemyResource, MazeResource

Plugins - Feature modules:

  • PlayerPlugin, EnemyPlugin, WorldPlugin

๐Ÿš€ Getting Started

Prerequisites

  • Rust 1.70 or higher
  • Cargo (comes with Rust)
  • Git

Installation

1. Clone the repository

git clone https://github.com/mamadbah2/multiplayer-fps.git
cd multiplayer-fps

2. Build the project

cargo build --release

This will compile both client and server binaries.


๐ŸŽฎ How to Play

Starting the Server

Option 1: Using Cargo

cargo run --bin server --release

Option 2: Using the compiled binary

./target/release/server

Server Configuration:

Enter the number of players: (default 2) 
> 4

The server will:

  • Start listening on 0.0.0.0:8080
  • Wait for the specified number of players to connect
  • Automatically start the game when lobby is full

Starting the Client

Option 1: Using Cargo

cargo run --bin client --release

Option 2: Using the compiled binary

./target/release/client

Client Configuration:

Enter your name: 
> Player1

Enter the server address (default: 192.168.1.100:8080): 
> localhost:8080

The client will:

  • Connect to the server
  • Wait in lobby until all players join
  • Start rendering the game when ready

๐ŸŽฎ Controls

Movement

  • W - Move forward
  • A - Move left
  • S - Move backward
  • D - Move right

Combat

  • Mouse - Look around / Aim
  • Left Click - Shoot
  • Spacebar - Jump (if enabled)

UI

  • ESC - Exit game
  • F3 - Toggle debug info (FPS, position)

๐ŸŒ Networking

Protocol Design

Message Types:

pub enum Message {
    Join { name: String },
    
    PlayerUpdateSending {
        position: Vec3,
        rotation: Quat,
        all_dead_players: Vec<String>,
    },
    
    PlayerUpdateReceiving {
        name: String,
        position: Vec3,
        rotation: Quat,
        all_dead_players: Vec<String>,
    },
    
    StartGame {
        player: CommonPlayer,
        enemies: Vec<CommonPlayer>,
    },
    
    Leave,
}

Network Architecture

Server:

  • UDP socket binding on port 8080
  • Broadcast system for player updates
  • 20 Hz tick rate
  • Player state management with RwLock

Client:

  • Asynchronous message receiving
  • 20 Hz update sending
  • Non-blocking socket operations
  • Client-side prediction

Serialization

Uses Bincode for efficient binary serialization:

  • Compact message size (~64 bytes per update)
  • Fast encoding/decoding
  • Zero-copy deserialization where possible

๐ŸŽจ Graphics & Physics

Bevy Rendering Pipeline

  1. Setup Phase:

    • Load 3D models and materials
    • Spawn entities (player, enemies, world)
    • Setup camera and lighting
  2. Update Phase (60 FPS target):

    • Process input
    • Update physics
    • Network synchronization
    • Animation updates
  3. Render Phase:

    • Frustum culling
    • Shadow mapping
    • Material rendering
    • UI overlay

Rapier3D Integration

Colliders:

Collider::cuboid(0.7, 0.1, 0.7)  // Player
Collider::cuboid(2.0, 5.0, 2.0)  // Wall
Collider::ball(0.1)              // Bullet

Physics Configuration:

RigidBody::Dynamic              // Player & bullets
RigidBody::Fixed                // Walls & floor
GravityScale(0.0)              // Disabled for FPS
LockedAxes::ROTATION_LOCKED    // Prevent player tipping

๐ŸŽต Audio System

Sound Effects

  • Footsteps: Looped during movement
  • Gunshots: Triggered on fire
  • Impacts: Bullet hit sounds

Implementation:

AudioPlayer::new(asset_server.load("sounds/running.ogg"))

Playback controlled by movement state.


๐Ÿ“Š Performance

Optimization Strategies

Compile-time:

[profile.dev]
opt-level = 1                    # Basic optimization

[profile.dev.package."*"]
opt-level = 3                    # Full optimization for dependencies

[profile.release]
lto = true                       # Link-time optimization
codegen-units = 1               # Single codegen unit

Runtime:

  • Entity pooling for bullets
  • Spatial partitioning for collision
  • LOD system for distant players
  • Update rate limiting (20 Hz networking)

Target Performance

  • 60 FPS minimum (client rendering)
  • < 50ms network latency
  • < 100ms input response time
  • 10 concurrent players supported

๐Ÿ› Debugging

Development Tools

Bevy Dev Tools:

bevy_dev_tools = "0.15.2"

Features:

  • FPS overlay (green, top-right)
  • Entity inspector
  • Resource browser
  • System profiler

Rapier Debug Rendering:

RapierDebugRenderPlugin::default()

Visualizes:

  • Colliders (wireframe)
  • Rigid bodies (colored)
  • Contact points

๐Ÿšง Known Issues & Limitations

  • Player Limit: Maximum 10 concurrent players
  • Lag Compensation: Basic interpolation only
  • Collision: Occasional bullet pass-through at high speeds
  • Audio: No spatial audio attenuation yet

๐Ÿ—บ๏ธ Roadmap

Planned Features

  • ๐ŸŽฏ Raycast-based shooting (hitscan)
  • ๐Ÿ† Scoreboard and kill/death tracking
  • ๐ŸŽจ Character models and animations
  • ๐Ÿ—บ๏ธ Multiple map support
  • ๐Ÿ”Š Spatial 3D audio
  • ๐ŸŽฎ Gamepad support
  • ๐ŸŒ Matchmaking system
  • ๐Ÿ’พ Save/load game state
  • ๐Ÿ… Achievement system
  • ๐ŸŽฅ Spectator mode

Future Improvements

  • Lag compensation with server reconciliation
  • Client-side prediction improvements
  • Anti-cheat measures
  • Better error handling and recovery
  • Performance profiling and optimization
  • Cross-platform testing (Windows, Linux, macOS)

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Write idiomatic Rust code
  • Follow Bevy's ECS best practices
  • Add documentation for public APIs
  • Include tests for new features
  • Keep commits atomic and well-described

๐Ÿ“š Learning Resources

Rust Game Development

Multiplayer Networking


๐Ÿ“„ License

This project is available for educational purposes.


๐Ÿ“ง Contact

Mamadou Bah - @mamadbah2

Project Link: https://github.com/mamadbah2/multiplayer-fps


๐Ÿ™ Acknowledgments

  • Bevy Engine Team - For the amazing game engine
  • Rapier Physics - For the robust physics library
  • Tokio Team - For async runtime
  • Rust Community - For excellent documentation and support

๐ŸŽฎ Built with Rust & Bevy for Learning Game Development ๐ŸŽฎ

Rust Bevy

โญ If you found this project helpful, please give it a star! โญ

About

A modern multiplayer first-person shooter built from scratch with Rust and Bevy Engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •