man it took me so long to find out that Rust has a `ref` keyword lol
This commit is contained in:
parent
214e0ceedc
commit
245dfde91e
2 changed files with 25 additions and 3 deletions
|
@ -1,5 +1,8 @@
|
|||
use avian2d::prelude::*;
|
||||
use bevy::prelude::*;
|
||||
use bevy::{
|
||||
input::mouse::{AccumulatedMouseScroll, MouseScrollUnit},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use super::objects::Player;
|
||||
|
||||
|
@ -38,3 +41,18 @@ pub fn move_camera(
|
|||
) {
|
||||
camera.translation = camera.translation.lerp(player.translation, 0.05);
|
||||
}
|
||||
|
||||
pub fn zoom_camera(
|
||||
mut camera: Single<&mut Projection, With<IsDefaultUiCamera>>,
|
||||
scroll: Res<AccumulatedMouseScroll>,
|
||||
) -> Result {
|
||||
let Projection::Orthographic(ref mut projection) = **camera else {
|
||||
return Err("Default camera was not orthographic".into());
|
||||
};
|
||||
let scroll_type_multiplier = match scroll.unit {
|
||||
MouseScrollUnit::Line => 0.01,
|
||||
MouseScrollUnit::Pixel => 0.001,
|
||||
};
|
||||
projection.scale = (projection.scale - scroll.delta.y * scroll_type_multiplier).clamp(0.1, 2.5);
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue