How to move camera arbitrary of user input in Bevy

Viewed 1860

I've used Camera2dBundle to import sprites and backgrounds into the scene I'm setting up. But I'm not sure how to move the camera independently of the sprite movements. Basically I don't want the camera to follow the player. I want it to constantly move in a single direction regardless of user input. I've tried:

fn move_camera(mut camera: Query<&mut Transform, With<Camera>>)   {
  
     for mut transform in camera.iter_mut() {
        
            transform.translation.x += 5.0; 
     }  

However this moves the player's x position

I see transform is made of these items:

Transform { translation: Vec3(0.0, 0.0, 999.9), rotation: Quat(0.0, 0.0, 0.0, 1.0), scale: Vec3(1.0, 1.0, 1.0) }

Here's how I'm accepting user input:

if keyboard_input.pressed(KeyCode::Right) {
            transform.translation.x += 2.0 * 5.0;
            transform.rotation = Quat::from_rotation_y(0.0).into();
            *atlas = player.run.clone();

Is there a better way to do this? Can I add an item to transform? Or what modification can I make?

1 Answers

Solved it. Not really the answer I wanted, but simply adding a movement for the player in the opposite directions works.

// added
transform.translation.x -= -1.0 * 5.0;
//
if keyboard_input.pressed(KeyCode::Right)
    transform.translation.x += 2.0 * 5.0;
    transform.rotation =   
    Quat::from_rotation_y(0.0).into();
        *atlas = player.run.clone();
Related