New to rust and bevy and I was trying to make a basic entity of Player move up. I gave the player a Transform component and I also gave the player a MaterialMesh2dBundle component for rendering a basic 2D circle. I thought that I would have to update the transform of the MaterialMesh2dBundle to have the same translation of the player's transform, but it seems like the circle is already updating its position without me telling it to, only the other transform component the player has. Can someone pls explain what is happening here and why it is happening?
struct Player;
#[derive(Component)]
struct Name(String);
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn(Camera2dBundle::default());
let shape = Mesh2dHandle(meshes.add(Circle { radius: 25.0 }));
let color = Color::hsl(360., 0.95, 0.7);
let mut player = commands.spawn(Player);
let mut player_transform = Transform::from_xyz(1000., 0., 0.);
let player_mesh = MaterialMesh2dBundle {
mesh: shape,
transform: Transform::from_xyz(0., 0., 0.),
material: materials.add(color),
..default()
};
player.insert(Name(String::from("Player")));
player.insert(player_transform);
player.insert(player_mesh);
}
fn update_player(time: Res<Time>, mut query: Query<(&mut Transform, &Name), With<Player>>) {
let speed:f32 = 50.0;
for mut q in &mut query {
let mut pos = &mut q.0;
pos.translation.y += speed * time.delta_seconds();;
}
}```