From a8b738a1d6a83586b825da6cf2e6c7e890f8252d Mon Sep 17 00:00:00 2001 From: -karlos- Date: Fri, 1 Dec 2023 17:10:17 +0100 Subject: [PATCH] added update_camera_speed --- src/flycam.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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>,