Skip to content

Commit

Permalink
added update_camera_speed
Browse files Browse the repository at this point in the history
  • Loading branch information
-karlos- committed Dec 1, 2023
1 parent 0fe239a commit a8b738a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/flycam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -112,6 +115,18 @@ fn setup(
keys.toggle_grab_cursor = KeyCode::G;
}


fn update_camera_speed(
mut movement_settings: ResMut<MovementSettings>,
fly_cam: Query<&Transform, (With<FlyCam>, Without<TileMap>)>,
tilemap: Query<&Transform, (With<TileMap>, Without<FlyCam>)>,
) {
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<Input<MouseButton>>,
Expand Down

0 comments on commit a8b738a

Please sign in to comment.