diff --git a/src/camera.rs b/src/camera.rs index e7b0ee8..d2a9eea 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -32,6 +32,7 @@ impl Plugin for CameraPlugin { #[derive(Resource)] pub struct MapCam { + pub initialized: bool, pub zoom_level: f32, pub target_zoom_level: f32, pub pitch: f32, @@ -40,8 +41,9 @@ pub struct MapCam { impl Default for MapCam { fn default() -> Self { Self { - zoom_level: 10.0, - target_zoom_level: 10000.0, + initialized: false, + zoom_level: 2.0, + target_zoom_level: 10.0, pitch: PI * 0.3, yaw: 0.0, } @@ -143,11 +145,17 @@ pub fn update_map_camera( mapcam.yaw += mouse_delta.x / 180.0 * settings.mouse_sensitivity; // 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) { mapcam.target_zoom_level = (mapcam.target_zoom_level * 1.1).min(17e18); } 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) mapcam.zoom_level = zoom_speed * mapcam.target_zoom_level + (1.0 - zoom_speed) * mapcam.zoom_level;