camera following bird works

main
Elijah Voigt 3 months ago
parent c6838a3fc5
commit 9d5caadbf4

@ -1,4 +1,4 @@
use bevy::{input::common_conditions::input_just_released, render::view::VisibleEntities}; use bevy::input::common_conditions::input_just_released;
use games::*; use games::*;
fn main() { fn main() {
@ -37,6 +37,8 @@ fn main() {
.run_if(in_state(PlayerState::Alive)), .run_if(in_state(PlayerState::Alive)),
// Rewinding systems // Rewinding systems
rewind.run_if(in_state(PlayerState::Rewind)), rewind.run_if(in_state(PlayerState::Rewind)),
// Camera follows when bird moves regardless of player state
camera_follow_bird.run_if(any_component_changed::<Transform>),
), ),
) )
.run(); .run();
@ -248,3 +250,10 @@ fn kill_bird(
debug!("Killing bird"); debug!("Killing bird");
**bird = RigidBody::Static; **bird = RigidBody::Static;
} }
fn camera_follow_bird(
bird: Single<&Transform, (With<Bird>, Changed<Transform>)>,
mut camera: Single<&mut Transform, (With<Camera>, Without<Bird>)>
) {
camera.translation.x = bird.translation.x;
}

@ -19,7 +19,7 @@ impl Plugin for DebuggingPlugin {
( (
(toggle_state_visibility::<DebuggingState>,) (toggle_state_visibility::<DebuggingState>,)
.run_if(state_changed::<DebuggingState>), .run_if(state_changed::<DebuggingState>),
toggle_debug_state.run_if(on_keyboard_press(KeyCode::F12)), toggle_debug_state.run_if(input_just_pressed(KeyCode::F12)),
(toggle_light_gizmo, toggle_aabb_gizmo).run_if(state_changed::<DebuggingState>), (toggle_light_gizmo, toggle_aabb_gizmo).run_if(state_changed::<DebuggingState>),
( (
(hover_mesh, hover_ui) (hover_mesh, hover_ui)

@ -14,3 +14,37 @@ pub fn any_component_changed<T: Component>(q: Query<Entity, Changed<T>>) -> bool
pub fn on_keyboard_press(key: KeyCode) -> impl FnMut(Res<ButtonInput<KeyCode>>) -> bool { pub fn on_keyboard_press(key: KeyCode) -> impl FnMut(Res<ButtonInput<KeyCode>>) -> bool {
move |keys: Res<ButtonInput<KeyCode>>| keys.just_pressed(key) move |keys: Res<ButtonInput<KeyCode>>| keys.just_pressed(key)
} }
/*
/// TODO: Make these work:
use bevy::ecs::query::{ArchetypeFilter, QueryData, QueryFilter};
pub fn filter_contains_exactly<F>(n: usize) -> impl FnMut(Query<Entity, F>) -> bool
where
F: QueryFilter + ArchetypeFilter
{
move |q: Query<Entity, F>| q.iter().len() == n
}
pub fn filter_contains_at_least<F>(n: usize) -> impl FnMut(Query<Entity, F>) -> bool
where
F: QueryFilter + ArchetypeFilter
{
move |q: Query<Entity, F>| q.iter().len() >= n
}
pub fn filter_contains_at_most<F>(n: usize) -> impl FnMut(Query<Entity, F>) -> bool
where
F: QueryFilter + ArchetypeFilter
{
move |q: Query<Entity, F>| q.iter().len() <= n
}
pub fn filter_is_empty<F>() -> impl FnMut(Query<Entity, F>) -> bool
where
F: QueryFilter + ArchetypeFilter
{
move |q: Query<Entity, F>| q.iter().len() == 0
}
*/

Loading…
Cancel
Save