You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bevy-workshop/src/2-basics/actual-physics.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,18 +23,17 @@ Let's pick a physics engine that's easy to use with Bevy. There are two options:
23
23
24
24
We'll use Avian in this workshop, but you could use Rapier and get similar results.
25
25
26
-
First we'll add a dependency on `avian2d` to our `Cargo.toml` file:
26
+
First we'll add a dependency on `avian2d` to our project:
27
27
28
28
```toml
29
-
[dependencies]
30
-
avian2d = "0.3"
29
+
cargo add avian2d
31
30
```
32
31
33
32
To finish the setup, we need to add the `PhysicsPlugins::default()` to our app. And as we're in space, let's remove gravity! This can be done by adding the resource `Gravity::ZERO`.
34
33
35
34
## Asteroid Movements
36
35
37
-
Asteroids are the easiest to do! First remove the `inertia` system, as that will now be handled by the physics engine.
36
+
Asteroids are the easiest to do! First remove the `inertia` system, and the fields of the `Asteroid` component, as that will now be handled by the physics engine.
38
37
39
38
When spawning an asteroid, we'll need to add the following components:
Copy file name to clipboardExpand all lines: bevy-workshop/src/2-basics/controls.md
+13-6Lines changed: 13 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
We'll control our player with the `A` and `D` keys on the keyboard to turn, and `W` for thrust.
4
4
5
+
Let's start by handling rotation:
6
+
5
7
```rust,no_run
6
8
# extern crate bevy;
7
9
# use bevy::prelude::*;
@@ -11,17 +13,18 @@ We'll control our player with the `A` and `D` keys on the keyboard to turn, and
11
13
fn control_player(
12
14
keyboard_input: Res<ButtonInput<KeyCode>>,
13
15
mut player: Query<&mut Transform, With<Player>>,
16
+
time: Res<Time>,
14
17
) -> Result {
15
18
let mut player_transform = player.single_mut()?;
19
+
20
+
let fixed_rotation_rate = 0.2;
21
+
let rotation_rate = fixed_rotation_rate / (1.0 / (60.0 * time.delta().as_secs_f32()));
22
+
16
23
if keyboard_input.pressed(KeyCode::KeyA) {
17
-
player_transform.rotate_z(FRAC_PI_8 / 4.0);
24
+
player_transform.rotate_z(rotation_rate);
18
25
}
19
26
if keyboard_input.pressed(KeyCode::KeyD) {
20
-
player_transform.rotate_z(-FRAC_PI_8 / 4.0);
21
-
}
22
-
if keyboard_input.pressed(KeyCode::KeyW) {
23
-
let forward = player_transform.local_y();
24
-
player_transform.translation += forward * 5.0;
27
+
player_transform.rotate_z(-rotation_rate);
25
28
}
26
29
Ok(())
27
30
}
@@ -57,6 +60,10 @@ Bevy exposes helper methods to manipulate the `Transform`:
57
60
58
61
As Bevy doesn't specialize for 2D, `Transform` has all the needed part for 3D and can be a bit hard to use in 2D.
59
62
63
+
## Time Delta
64
+
65
+
TODO
66
+
60
67
## Error handling in systems
61
68
62
69
Bevy systems can return a [`Result`](https://docs.rs/bevy/0.16.0/bevy/ecs/error/type.Result.html) (an alias to `Result<(), BevyError>`) to be able to use error handling, like `?`.
Copy file name to clipboardExpand all lines: bevy-workshop/src/2-basics/display.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Displaying Something
2
2
3
+
Let's start building a game! First step is to add a new `Game` variant to the `GameState` enum, and change to it in the menu instead of just printing something.
4
+
3
5
We'll just display blocks of color for now, as placeholders. Red is the player, blue is an asteroid.
4
6
5
7
```rust,no_run
@@ -8,7 +10,7 @@ We'll just display blocks of color for now, as placeholders. Red is the player,
Copy file name to clipboardExpand all lines: bevy-workshop/src/2-basics/exercises2.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,22 @@
2
2
3
3
It's very easy to avoid collisions with the asteroids as they don't move... Let's make this game a bit harder!
4
4
5
+
You can continue from your code, or get the branch with the workshop up till now:
6
+
7
+
```sh
8
+
git checkout 06-basic-game-mid
9
+
```
10
+
11
+
Let's review what was changed: <https://github.com/vleue/bevy_workshop-rustweek-2025/compare/06-basic-game..06-basic-game-mid>
12
+
5
13
## Moving the Asteroids
6
14
7
15
Make the asteroids move in random directions, at random speeds.
8
16
9
17
Tips:
10
18
11
19
- Add information about direction and speed to the `Asteroid` component.
20
+
- Add the rand crate (`cargo add rand@0.8`) to set them to random values with [`Rng::gen_range`](https://docs.rs/rand/0.8.5/rand/trait.Rng.html#method.gen_range)
12
21
- Add a system to update the position of the asteroids based on their direction and speed.
13
22
14
23
## Losing the Game
@@ -17,7 +26,7 @@ Let's go back to the menu when colliding with an asteroid.
17
26
18
27
Tips:
19
28
20
-
- Use the `ResMut<NextState<GameStates>>` system parameter to change the current state on collision
29
+
- Use the `ResMut<NextState<GameState>>` system parameter to change the current state on collision
Copy file name to clipboardExpand all lines: bevy-workshop/src/3-level/loading.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,12 @@ pub struct Level {
26
26
27
27
## Asset Loader
28
28
29
+
Let's add `thiserror` as a dependency, this will help us when declaring the kind of errors that can happen when loading our file.
30
+
31
+
```sh
32
+
cargo add thiserror
33
+
```
34
+
29
35
To load this format, we'll read the file character by character, then choose the right tile depending on the character. Bevy expects custom asset loader to implement the trait [`AssetLoader`](https://docs.rs/bevy/0.16.0/bevy/asset/trait.AssetLoader.html).
30
36
31
37
```rust
@@ -108,7 +114,7 @@ Custom asset formats and loaders must be initiated in the application with [`App
Copy file name to clipboardExpand all lines: bevy-workshop/src/5-sound/firing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ fn fire_laser(
71
71
72
72
To receive an event, we must use the [`EventReader`](https://docs.rs/bevy/0.16.0/bevy/ecs/event/struct.EventReader.html) system parameter, and by calling [`EventReader::read`](https://docs.rs/bevy/0.16.0/bevy/ecs/event/struct.EventReader.html#method.read) we can iterate over events.
73
73
74
-
To play audio, we must spawn an entity with the [`AudioStart`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioStart.html) component that will contain an [`Handle`](https://docs.rs/bevy/0.16.0/bevy/asset/enum.Handle.html) to the [`AudioSource`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioSource.html) asset.
74
+
To play audio, we must spawn an entity with the [`AudioPlayer`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioPlayer.html) component that will contain an [`Handle`](https://docs.rs/bevy/0.16.0/bevy/asset/enum.Handle.html) to the [`AudioSource`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.AudioSource.html) asset.
75
75
76
76
By default, audio entities remain present once the audio is done playing. You can change this behaviour with the component [`PlaybackSettings::DESPAWN`](https://docs.rs/bevy/0.16.0/bevy/audio/struct.PlaybackSettings.html#associatedconstant.DESPAWN).
0 commit comments