Plonq / bevy_rts_camera

RTS-style camera controls plugin for Bevy Engine
Apache License 2.0
59 stars 6 forks source link

Temporarily turn off movement at will #16

Closed Joakker closed 6 months ago

Joakker commented 6 months ago

The problem

I'll explain what I want to do: When focusing on the game's UI, the camera shouldn't react to the player's input. For example, if there's a side panel that the player must click, the camera shouldn't move when approaching the window edge. If there's a list to scroll through, the camera shouldn't zoom when the mouse is over that list.

Possible solution

Provide a resource, for example

#[derive(Resource, Default)]
pub struct SkipMovement;

That you can add when you need to keep the camera still, and then in src/controller.rs

impl Plugin for RtsCameraControlsPlugin {
    fn build(&self, app: &mut App) {
        app.add_plugins(DefaultRaycastingPlugin).add_systems(
            Update,
            (zoom, pan, grab_pan, rotate)
                .run_if(not(resource_exists::<SkipMovement>()))
                .before(RtsCameraSystemSet),
        );
    }
}

That way, while the resource exists, the camera won't react to the player's input, and you can remove the resource when defocusing the UI.

Plonq commented 6 months ago

There's an enabled attribute to the RtsCameraControls component. Is that not suitable?

Can toggle like this:

fn toggle_camera_controls_system(
    key_input: Res<ButtonInput<KeyCode>>,
    mut controls_q: Query<&mut RtsCameraControls>,
) {
    if key_input.just_pressed(KeyCode::KeyT) {
        for mut controls in controls_q.iter_mut() {
            controls.enabled = !controls.enabled;
        }
    }
}
Joakker commented 6 months ago

Oh sorry, I'm dumb. I hadn't seen that