├── .gitignore ├── README.md └── third_person_beginner ├── README.md ├── assets └── demo.gif ├── tutorial_1 ├── Cargo.toml └── src │ └── main.rs ├── tutorial_2 ├── Cargo.toml └── src │ ├── camera.rs │ ├── main.rs │ ├── player.rs │ └── world.rs ├── tutorial_3 ├── Cargo.toml └── src │ ├── camera.rs │ ├── main.rs │ ├── player.rs │ └── world.rs ├── tutorial_4 ├── Cargo.toml └── src │ ├── camera.rs │ ├── main.rs │ ├── player.rs │ └── world.rs ├── tutorial_5 ├── Cargo.toml ├── assets │ └── Player.gltf └── src │ ├── camera.rs │ ├── main.rs │ ├── player.rs │ └── world.rs ├── tutorial_6 ├── Cargo.toml ├── assets │ └── Player.gltf └── src │ ├── camera.rs │ ├── main.rs │ ├── player.rs │ └── world.rs ├── tutorial_7 ├── Cargo.toml ├── assets │ └── Player.gltf └── src │ ├── camera.rs │ ├── main.rs │ ├── player.rs │ └── world.rs └── tutorial_8 ├── Cargo.toml ├── assets └── Player.gltf └── src ├── camera.rs ├── main.rs ├── player.rs └── world.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 8 | Cargo.lock 9 | 10 | # These are backup files generated by rustfmt 11 | **/*.rs.bk 12 | 13 | # MSVC Windows builds of rustc generate these, which store debugging information 14 | *.pdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Bevy Tutorials 2 | 3 | The master branch contains the latest version of Bevy. Select the appropriate branch for specific versions. -------------------------------------------------------------------------------- /third_person_beginner/README.md: -------------------------------------------------------------------------------- 1 | # Third Person Tutorial 2 | 3 | ![Demo](assets/demo.gif) -------------------------------------------------------------------------------- /third_person_beginner/assets/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/The-DevBlog/bevy_tutorials/0dd8597da62270c1bedcf1465224e45a8c959bd3/third_person_beginner/assets/demo.gif -------------------------------------------------------------------------------- /third_person_beginner/tutorial_1/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tutorial_1" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | bevy = "0.15.1" 10 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_1/src/main.rs: -------------------------------------------------------------------------------- 1 | use bevy::{prelude::*, DefaultPlugins}; 2 | use bevy::color::palettes::css; 3 | 4 | const COLOR_DARK_GREEN: Color = Color::Srgba(css::DARK_GREEN); 5 | const COLOR_BLUE: Color = Color::Srgba(css::BLUE); 6 | 7 | fn main() { 8 | App::new() 9 | .add_plugins(DefaultPlugins) 10 | .add_systems( 11 | Startup, 12 | (spawn_player, spawn_camera, spawn_floor, spawn_light), 13 | ) 14 | .run(); 15 | } 16 | 17 | fn spawn_camera(mut commands: Commands) { 18 | let camera = ( 19 | Camera3d::default(), 20 | Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), 21 | ); 22 | 23 | commands.spawn(camera); 24 | } 25 | 26 | fn spawn_floor( 27 | mut commands: Commands, 28 | mut meshes: ResMut>, 29 | mut materials: ResMut>, 30 | ) { 31 | let floor = ( 32 | Mesh3d(meshes.add(Mesh::from(Plane3d::default().mesh().size(15.0, 15.0)))), 33 | MeshMaterial3d(materials.add(COLOR_DARK_GREEN)), 34 | ); 35 | 36 | commands.spawn(floor); 37 | } 38 | 39 | fn spawn_player( 40 | mut commands: Commands, 41 | mut meshes: ResMut>, 42 | mut materials: ResMut>, 43 | ) { 44 | let player = ( 45 | Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), 46 | MeshMaterial3d(materials.add(COLOR_BLUE)), 47 | Transform::from_xyz(0.0, 0.5, 0.0), 48 | ); 49 | 50 | commands.spawn(player); 51 | } 52 | 53 | fn spawn_light(mut commands: Commands) { 54 | let light = ( 55 | PointLight { 56 | intensity: 2000.0 * 1000.0, 57 | ..default() 58 | }, 59 | Transform::from_xyz(0.0, 5.0, 0.0), 60 | ); 61 | 62 | commands.spawn(light); 63 | } 64 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_2/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tutorial_2" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | bevy = "0.15.1" 10 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_2/src/camera.rs: -------------------------------------------------------------------------------- 1 | use bevy::prelude::*; 2 | 3 | pub struct CameraPlugin; 4 | 5 | impl Plugin for CameraPlugin { 6 | fn build(&self, app: &mut App) { 7 | app.add_systems(Startup, spawn_camera); 8 | } 9 | } 10 | 11 | fn spawn_camera(mut commands: Commands) { 12 | let camera = ( 13 | Camera3d::default(), 14 | Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), 15 | ); 16 | commands.spawn(camera); 17 | } 18 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_2/src/main.rs: -------------------------------------------------------------------------------- 1 | use bevy::{prelude::*, DefaultPlugins}; 2 | use camera::CameraPlugin; 3 | use player::PlayerPlugin; 4 | use world::WorldPlugin; 5 | 6 | mod camera; 7 | mod player; 8 | mod world; 9 | 10 | fn main() { 11 | App::new() 12 | .add_plugins((DefaultPlugins, PlayerPlugin, WorldPlugin, CameraPlugin)) 13 | .run(); 14 | } 15 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_2/src/player.rs: -------------------------------------------------------------------------------- 1 | use bevy::prelude::*; 2 | 3 | use bevy::color::palettes::css; 4 | const COLOR_BLUE: Color = Color::Srgba(css::BLUE); 5 | 6 | pub struct PlayerPlugin; 7 | 8 | impl Plugin for PlayerPlugin { 9 | fn build(&self, app: &mut App) { 10 | app.add_systems(Startup, spawn_player); 11 | } 12 | } 13 | 14 | fn spawn_player( 15 | mut commands: Commands, 16 | mut meshes: ResMut>, 17 | mut materials: ResMut>, 18 | ) { 19 | let player = ( 20 | Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), 21 | MeshMaterial3d(materials.add(COLOR_BLUE)), 22 | Transform::from_xyz(0.0, 0.5, 0.0), 23 | ); 24 | 25 | commands.spawn(player); 26 | } 27 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_2/src/world.rs: -------------------------------------------------------------------------------- 1 | use bevy::prelude::*; 2 | 3 | use bevy::color::palettes::css; 4 | const COLOR_DARK_GREEN: Color = Color::Srgba(css::DARK_GREEN); 5 | 6 | pub struct WorldPlugin; 7 | 8 | impl Plugin for WorldPlugin { 9 | fn build(&self, app: &mut App) { 10 | app.add_systems(Startup, (spawn_floor, spawn_light)); 11 | } 12 | } 13 | 14 | fn spawn_floor( 15 | mut commands: Commands, 16 | mut meshes: ResMut>, 17 | mut materials: ResMut>, 18 | ) { 19 | let floor = ( 20 | Mesh3d(meshes.add(Mesh::from(Plane3d::default().mesh().size(15.0, 15.0)))), 21 | MeshMaterial3d(materials.add(COLOR_DARK_GREEN)), 22 | ); 23 | 24 | commands.spawn(floor); 25 | } 26 | 27 | fn spawn_light(mut commands: Commands) { 28 | let light = ( 29 | PointLight { 30 | intensity: 2000.0 * 1000.0, 31 | ..default() 32 | }, 33 | Transform::from_xyz(0.0, 5.0, 0.0), 34 | ); 35 | 36 | commands.spawn(light); 37 | } 38 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_3/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tutorial_3" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | bevy = "0.15.1" 10 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_3/src/camera.rs: -------------------------------------------------------------------------------- 1 | use bevy::prelude::*; 2 | 3 | pub struct CameraPlugin; 4 | 5 | impl Plugin for CameraPlugin { 6 | fn build(&self, app: &mut App) { 7 | app.add_systems(Startup, spawn_camera); 8 | } 9 | } 10 | 11 | fn spawn_camera(mut commands: Commands) { 12 | let camera = ( 13 | Camera3d::default(), 14 | Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), 15 | ); 16 | commands.spawn(camera); 17 | } 18 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_3/src/main.rs: -------------------------------------------------------------------------------- 1 | use bevy::{prelude::*, DefaultPlugins}; 2 | use camera::CameraPlugin; 3 | use player::PlayerPlugin; 4 | use world::WorldPlugin; 5 | 6 | mod camera; 7 | mod player; 8 | mod world; 9 | 10 | fn main() { 11 | App::new() 12 | .add_plugins((DefaultPlugins, PlayerPlugin, WorldPlugin, CameraPlugin)) 13 | .run(); 14 | } 15 | -------------------------------------------------------------------------------- /third_person_beginner/tutorial_3/src/player.rs: -------------------------------------------------------------------------------- 1 | use bevy::prelude::*; 2 | 3 | use bevy::color::palettes::css; 4 | const COLOR_BLUE: Color = Color::Srgba(css::BLUE); 5 | 6 | pub struct PlayerPlugin; 7 | 8 | impl Plugin for PlayerPlugin { 9 | fn build(&self, app: &mut App) { 10 | app.add_systems(Startup, spawn_player) 11 | .add_systems(Update, player_movement); 12 | } 13 | } 14 | 15 | #[derive(Component)] 16 | struct Player; 17 | 18 | #[derive(Component)] 19 | struct Speed(f32); 20 | 21 | fn spawn_player( 22 | mut commands: Commands, 23 | mut meshes: ResMut>, 24 | mut materials: ResMut>, 25 | ) { 26 | let player = ( 27 | ( 28 | Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), 29 | MeshMaterial3d(materials.add(COLOR_BLUE)), 30 | Transform::from_xyz(0.0, 0.5, 0.0), 31 | ), 32 | Player, 33 | Speed(2.5), 34 | ); 35 | 36 | commands.spawn(player); 37 | } 38 | 39 | fn player_movement( 40 | time: Res