diff --git a/src/flycam.rs b/src/flycam.rs index 1ba7d9f..eccaee9 100644 --- a/src/flycam.rs +++ b/src/flycam.rs @@ -8,11 +8,14 @@ use bevy::{ }; use bevy_flycam::{FlyCam, KeyBindings, MovementSettings, NoCameraPlayerPlugin}; +use crate::tilemap::TileMap; + pub struct Plugin; impl bevy::prelude::Plugin for Plugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup) + .add_systems(Update, update_camera_speed) .add_systems(Update, grab_cursor) .add_plugins(NoCameraPlayerPlugin); // https://github.com/sburris0/bevy_flycam (bevy_config_cam dies not work wiht Bevy 12) } @@ -112,6 +115,18 @@ fn setup( keys.toggle_grab_cursor = KeyCode::G; } + +fn update_camera_speed( + mut movement_settings: ResMut, + fly_cam: Query<&Transform, (With, Without)>, + tilemap: Query<&Transform, (With, Without)>, +) { + let speed = 1. * (fly_cam.single().translation.distance(tilemap.single().translation) - crate::geopos::EARTH_RADIUS); + movement_settings.speed = speed.clamp(0.1,1000.); +} + +// Todo ? Merge both to fn update? To many different parameters? + fn grab_cursor( mut windows: Query<&mut Window>, btn: Res>,