Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support enabling/disabling mouse/keyboard movement #3

Closed
wants to merge 5 commits into from

Conversation

superdump
Copy link
Contributor

I wanted to be able to enable/disable the FlyCamera movement systems so that I could use this crate for controlling the camera, and still be able to interact with UI elements.

I intend to use this with mouse_button_activate = Some(MouseButton::Right) and activate_is_toggle = false to work similarly to some other game engines I've used but I thought I'd make it a bit more flexible while I was at it. 😄

I've made it so that you can specify a mouse button or key to 'activate' motion, and then if activate_is_toggle is set, then pressing the button/key will toggle whether movement is activated, else if it is not set, you have to hold down the button/key for movement to be activated.

I also made the default be activate_is_toggle = true and no 'bindings' set, and the 'activate' state is true so that the default behaviour before this PR is preserved where movement is always on.

NOTE: This is based on PR #2 .

If activate_is_toggle is true, then the configured mouse button and/or
key will toggle movement on/off. If activate_is_toggle is false, then
the button must be held down to activate the fly camera movement
systems. This allows for example holding down the right mouse button for
navigating a scene or releasing it to interact with UI elements.
@mcpar-land
Copy link
Owner

I actually like the idea of a toggle quite a bit now that you mention it, but including a key-binding for it that must exist seems out of scope for the package.

Adding just a simple enabled bool would be sufficient, and having users program their own means of toggling wouldn't be super difficult, I imagine it's something you could do in just one system function.

@mcpar-land mcpar-land closed this Sep 20, 2020
@mcpar-land
Copy link
Owner

pub enabled: bool,

bevy_fly_camera/src/lib.rs

Lines 131 to 143 in 882b5f2

let (axis_h, axis_v, axis_float) = if options.enabled {
(
movement_axis(&keyboard_input, options.key_right, options.key_left),
movement_axis(
&keyboard_input,
options.key_backward,
options.key_forward,
),
movement_axis(&keyboard_input, options.key_up, options.key_down),
)
} else {
(0.0, 0.0, 0.0)
};

bevy_fly_camera/src/lib.rs

Lines 201 to 203 in 882b5f2

if !options.enabled {
continue;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants