2

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?

chiffre
  • 29
  • 1
  • 3
  • 2
    Could you provide a minimal example, please? https://stackoverflow.com/help/minimal-reproducible-example I realize creating a MWE is hard to do, but it would help a lot with answering the question. BTW, I guess that you can change the reference of the camera from the player to 'world' which should allow this. – Unapiedra Apr 08 '21 at 19:37

1 Answers1

0

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();
chiffre
  • 29
  • 1
  • 3