Skip to content

Conversation

fkesheh
Copy link

@fkesheh fkesheh commented Oct 14, 2025

Add RTS Game Proof of Concept

Objective

Implement a fully functional Real-Time Strategy (RTS) game proof of concept using Bevy 0.15, demonstrating core RTS mechanics including unit control, resource gathering, combat, and intelligent pathfinding.

Solution

Added real_time_strategy.rs - a complete RTS game implementation featuring:

Core Systems

  • Unit Selection System: Single-click and drag-to-select (box selection) with visual feedback via ground-based selection rings
  • Movement System: XZ-plane movement with waypoint-based pathfinding around obstacles
  • Pathfinding: Automatic obstacle avoidance for both buildings and resources with recursive waypoint generation
  • Collision System: Physical collisions between units, buildings, and resources with intelligent MoveTo cancellation
  • Combat System: Attack commands, range checking, and automatic target pursuit
  • Resource Gathering: Worker units collect resources and return them to base with manual assignment support
  • Unit Spawning: Keyboard shortcuts (Q/W) to spawn workers and warriors with ring-based positioning

Visual Features

  • Health Bars: Billboard health bars with team-based colors (blue/green for player, red for enemy)
  • Selection Rings: Emissive ground rings for selected units
  • Terrain: Procedurally generated grass and dirt patches for visual variety
  • UI: Resource counter, selection info, and control instructions

Technical Highlights

  • ECS Architecture: Proper use of Bevy's Entity-Component-System pattern
  • Collision Detection: XZ-plane distance calculations with directional blocking
  • Pathfinding Algorithm:
    • Ray-casting path validation
    • Perpendicular waypoint generation around obstacles
    • Recursive path finding for multiple obstacles
    • Clearance distances: 6.5 units (buildings), 1.2 units (resources)
  • Waypoint Navigation: Multi-waypoint traversal with automatic progression
  • Query Optimization: Proper component filtering to avoid query conflicts

Game Balance

  • Starting resources: 100
  • Worker cost: 25 (can gather resources)
  • Warrior cost: 50 (combat units)
  • Resource nodes: 100 units each

Testing

Tested manually with the following scenarios:

  • ✅ Single unit selection and box selection
  • ✅ Unit movement around buildings (3x3 cuboids)
  • ✅ Unit movement around resource nodes (spheres)
  • ✅ Pathfinding with multiple obstacles in a line
  • ✅ Resource gathering and return to base
  • ✅ Combat between player and enemy units
  • ✅ Unit spawning (workers and warriors)
  • ✅ Collision prevention during waypoint navigation
  • ✅ Health bar visibility and color coding

Known Limitations

  • Pathfinding uses simple perpendicular waypoints (not A* or navmesh)
  • No formation movement for multiple units
  • Selection box visual not rendered (simplified for POC)
  • No minimap or fog of war

Platforms Tested

  • macOS (Darwin 24.6.0)
  • Bevy 0.15

Showcase

Click to view key features

Pathfinding System

// Automatic waypoint generation around obstacles
let waypoints = find_path_around_obstacles(
    start_position,
    goal_position,
    &buildings,
    &resources,
);

// Waypoints component for multi-step navigation
#[derive(Component)]
struct Waypoints {
    points: Vec<Vec3>,
    current_index: usize,
}

Collision-Aware Navigation

// Movement only considers XZ plane (ground-based units)
let direction_xz = Vec3::new(
    target.x - transform.translation.x,
    0.0,
    target.z - transform.translation.z
);
let distance = direction_xz.length();

// Collision system respects waypoint navigation
if dot > 0.3 && distance < min_distance * 0.9 && !has_waypoints {
    commands.entity(entity).remove::<MoveTo>();
}

Controls

  • Left Click: Select single unit
  • Left Drag: Box select multiple units
  • Right Click: Move/Attack/Gather command
  • Q: Spawn Worker (costs 25 resources)
  • W: Spawn Warrior (costs 50 resources)
  • Arrow Keys: Move camera

Note: This is a proof of concept demonstrating RTS mechanics in Bevy. Production use would require additional features like proper AI, networking support, and performance optimizations for larger unit counts.

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@ChristopherBiscardi ChristopherBiscardi added the S-Nominated-To-Close A triage team member thinks this PR or issue should be closed out. label Oct 14, 2025
@ChristopherBiscardi
Copy link
Contributor

This PR targets a bevy version that is 2 versions out of date and seems to include un-labelled LLM-generated content. As such I've nominated it to be closed as it can not be accepted.

all forms of AI-generated contributions cannot be merged into repositories
maintained by the Bevy Organization

bevyengine/bevy-website#2204

@fkesheh fkesheh closed this Oct 14, 2025
@fkesheh
Copy link
Author

fkesheh commented Oct 14, 2025

Ok, I will read it through

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-Nominated-To-Close A triage team member thinks this PR or issue should be closed out.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants