better starting zoom level

This commit is contained in:
yuni 2024-04-19 04:41:07 +02:00
parent ed6187d996
commit 0044f50e68

View file

@ -32,6 +32,7 @@ impl Plugin for CameraPlugin {
#[derive(Resource)] #[derive(Resource)]
pub struct MapCam { pub struct MapCam {
pub initialized: bool,
pub zoom_level: f32, pub zoom_level: f32,
pub target_zoom_level: f32, pub target_zoom_level: f32,
pub pitch: f32, pub pitch: f32,
@ -40,8 +41,9 @@ pub struct MapCam {
impl Default for MapCam { impl Default for MapCam {
fn default() -> Self { fn default() -> Self {
Self { Self {
zoom_level: 10.0, initialized: false,
target_zoom_level: 10000.0, zoom_level: 2.0,
target_zoom_level: 10.0,
pitch: PI * 0.3, pitch: PI * 0.3,
yaw: 0.0, yaw: 0.0,
} }
@ -143,11 +145,17 @@ pub fn update_map_camera(
mapcam.yaw += mouse_delta.x / 180.0 * settings.mouse_sensitivity; mapcam.yaw += mouse_delta.x / 180.0 * settings.mouse_sensitivity;
// Update zoom level // Update zoom level
if !mapcam.initialized {
let factor = if target == player_transform { 100.0 } else { 1.0 };
mapcam.target_zoom_level *= target.scale.x * factor;
mapcam.zoom_level *= target.scale.x * factor;
mapcam.initialized = true;
}
if keyboard_input.pressed(settings.key_map_zoom_out) { if keyboard_input.pressed(settings.key_map_zoom_out) {
mapcam.target_zoom_level = (mapcam.target_zoom_level * 1.1).min(17e18); mapcam.target_zoom_level = (mapcam.target_zoom_level * 1.1).min(17e18);
} }
if keyboard_input.pressed(settings.key_map_zoom_in) { if keyboard_input.pressed(settings.key_map_zoom_in) {
mapcam.target_zoom_level = (mapcam.target_zoom_level / 1.1).max(2.0); mapcam.target_zoom_level = (mapcam.target_zoom_level / 1.1).max(target.scale.x);
} }
let zoom_speed = 0.05; // should be between 0.0001 (slow) and 1.0 (instant) let zoom_speed = 0.05; // should be between 0.0001 (slow) and 1.0 (instant)
mapcam.zoom_level = zoom_speed * mapcam.target_zoom_level + (1.0 - zoom_speed) * mapcam.zoom_level; mapcam.zoom_level = zoom_speed * mapcam.target_zoom_level + (1.0 - zoom_speed) * mapcam.zoom_level;