-
Hi everyone, I just started on my Bevy journey, and got stuck quicker than I expected :/ use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, move_circle)
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(50.).into()).into(),
material: materials.add(ColorMaterial::from(Color::PURPLE)),
transform: Transform::from_translation(Vec3::new(-150., 0., 0.)),
..default()
});
}
fn move_circle(mut circle: Query<(&mut Transform)>, timer: Res<Time>) {
for mut transform in &mut circle {
println!("WTF {}", transform.translation);
transform.translation.x += 150.0 * timer.delta_seconds();
}
} My console prints out what looks like I'd expect -- Increasing x values in the translation vector, but the circle just... sits there. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Don't be discouraged. This is a pretty common beginner mistake to make. You're moving the circle, but also the camera! To move only the circle, you can: Create a struct that we'll use a "marker component." #[derive(Component)]
struct Circle; Add it to your circle when you spawn it. commands.spawn((
MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(50.).into()).into(),
material: materials.add(ColorMaterial::from(Color::PURPLE)),
transform: Transform::from_translation(Vec3::new(-150., 0., 0.)),
..default()
},
Circle
)); Finally, add a query filter to your fn move_circle(mut circle: Query<&mut Transform, With<Circle>>, timer: Res<Time>) { /* ... */ } |
Beta Was this translation helpful? Give feedback.
Don't be discouraged. This is a pretty common beginner mistake to make. You're moving the circle, but also the camera!
To move only the circle, you can:
Create a struct that we'll use a "marker component."
Add it to your circle when you spawn it.
Finally, add a query filter to your
move_circle
system.