I am trying to move a sprite and the camera in a 2D top down game. I attempted to make two separate querys for the transform of the sprite and the camera transform.
fn move_character(
keyboard_input: Res<Input<KeyCode>>,
mut query: Query<(&mut Transform, &mut TextureAtlasSprite), With<Character>>,
mut camera_query: Query<&mut Transform, With<Camera>>,
time_step: Res<FixedTime>,){
let (mut transform, mut sprite) = query.single_mut();
let speed = 60.0;
if keyboard_input.pressed(KeyCode::Left) {
transform.translation.x += -speed*time_step.period.as_secs_f32();
sprite.index = 1;
}
if keyboard_input.pressed(KeyCode::Right) {
transform.translation.x += speed*time_step.period.as_secs_f32();
sprite.index = 6;
}
if keyboard_input.pressed(KeyCode::Up) {
transform.translation.y += speed*time_step.period.as_secs_f32();
sprite.index = 4;
}
if keyboard_input.pressed(KeyCode::Down) {
transform.translation.y += -speed*time_step.period.as_secs_f32();
sprite.index = 5;
}
}
Just by attempting to make the second query, I get a weird error with a message I don't understand. Should I be doing this in one query somehow?