//! A basic scene with some "terrain" and "units" to demonstrate how to set up a basic //! RTS camera. use bevy::prelude::*; use bevy_rts_camera::{Ground, RtsCamera, RtsCameraControls, RtsCameraPlugin}; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(RtsCameraPlugin) .add_systems(Startup, setup) .run(); } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { // Ground commands.spawn(( Mesh3d(meshes.add(Plane3d::default().mesh().size(80.0, 80.0))), MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), // Add `Ground` component to any entity you want the camera to treat as ground. Ground, )); // Some "terrain" let terrain_material = materials.add(Color::srgb(0.8, 0.7, 0.6)); commands.spawn(( Mesh3d(meshes.add(Cuboid::new(15.0, 1.0, 5.0))), MeshMaterial3d(terrain_material.clone()), Transform::from_xyz(15.0, 0.5, -5.0), Ground, )); commands.spawn(( Mesh3d(meshes.add(Cuboid::new(10.0, 5.0, 15.0))), MeshMaterial3d(terrain_material.clone()), Transform::from_xyz(-15.0, 2.5, 0.0), Ground, )); commands.spawn(( Mesh3d(meshes.add(Sphere::new(12.5))), MeshMaterial3d(terrain_material.clone()), Transform::from_xyz(0.0, 0.0, -23.0), Ground, )); // Some generic units that are not part of the 'Ground' (ignored for height calculation) for x in -5..5 { for z in -5..5 { commands.spawn(( Mesh3d(meshes.add(Capsule3d::new(0.25, 1.25))), MeshMaterial3d(terrain_material.clone()), Transform::from_xyz(x as f32 * 0.7, 0.75, z as f32 * 0.7), )); } } // Light commands.spawn(( DirectionalLight { illuminance: 1000.0, shadows_enabled: true, ..default() }, Transform::from_rotation(Quat::from_euler( EulerRot::YXZ, 150.0f32.to_radians(), -40.0f32.to_radians(), 0.0, )), )); // Camera commands.spawn((RtsCamera::default(), RtsCameraControls::default())); }