Corrosive-Games / bevy-parallax

Parallax background plugin for Bevy
MIT License
114 stars 17 forks source link

add CameraFollow component #32

Closed ettoreleandrotognoli closed 6 months ago

ettoreleandrotognoli commented 1 year ago

As we're using the ParallaxMoveEvent to move the camera, I want to provide some smart ways to generate it In that way I think less people needs to know the ParallaxMoveEvent internally

ParallaxMoveEvent now has tranlastion instead of camera_move_speed and rotation

The CameraFollow component will generate the ParallaxMoveEvent using the TranslateStrategy and RotationStrategy

I also updated the example in README and add a test to help us to keep it updated

Resolves #20

ettoreleandrotognoli commented 1 year ago
cargo run --example cyberpunk --features bevy-inspector-egui
let y_limit = Limit::zero_to(500.);
let x_pid = PID::new(0.1, 0.5, 0.01);
let y_pid = x_pid.with_integral_limit(Limit::new(-25., 25.));
let offset = Vec2::new(200., 0.);
let camera = commands
    .spawn(Camera2dBundle {
        transform: Transform::from_translation(offset.extend(0.)),
        ..default()
    })
    //.insert(CameraFollow::fixed(player).with_offset(offset))
    //.insert(CameraFollow::proportional(player, 0.1).with_offset(offset))
    .insert(CameraFollow::pid_xyz(player, &x_pid, &y_pid, &x_pid).with_offset(offset))
    .insert(ParallaxCameraComponent {
        limits: Vec2Limit::new(Limit::default(), y_limit),
        ..default()
    })
    .id();

https://github.com/Corrosive-Games/bevy-parallax/assets/4960560/5e412807-d476-49dc-9193-01d66ecf8194

cdsupina commented 1 year ago

Love this! Great addition!

cdsupina commented 8 months ago

We should get this merged too I didn't realize it was still sitting here unmerged. @ettoreleandrotognoli

ettoreleandrotognoli commented 8 months ago

I'll update it, and fix the conflicts this week

newclarityex commented 8 months ago

I would really appreciate this! I think having to control the camera purely through move speed is very janky to work around.

ettoreleandrotognoli commented 7 months ago

hello @cdsupina sorry the delay The PR is updated