mirror of
https://github.com/edg-l/teecity.git
synced 2024-11-09 09:38:22 +00:00
camera moves
This commit is contained in:
parent
a7c4802c6d
commit
cefff9652b
|
@ -1,3 +1,5 @@
|
|||
#![allow(clippy::type_complexity)]
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_ecs_tilemap::prelude::*;
|
||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
|
@ -27,6 +29,7 @@ fn main() {
|
|||
.add_systems((player::player_input, player::player_mouse).before(physics::move_system))
|
||||
.add_system(physics::move_system)
|
||||
.add_system(misc::aim_target_system.after(physics::move_system))
|
||||
.add_system(player::player_camera.after(misc::aim_target_system))
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -71,3 +71,28 @@ pub fn player_mouse(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn player_camera(
|
||||
mut query_player: Query<(&mut AimTarget, &Transform), (With<Player>, Without<MainCamera>)>,
|
||||
mut query_camera: Query<&mut Transform, With<MainCamera>>,
|
||||
) {
|
||||
let mut camera_transform = query_camera.single_mut();
|
||||
let (mut aim_target, player_transform) = query_player.single_mut();
|
||||
|
||||
let old = camera_transform.translation;
|
||||
|
||||
camera_transform.translation = Vec3::new(
|
||||
player_transform.translation.x,
|
||||
player_transform.translation.y,
|
||||
camera_transform.translation.z,
|
||||
);
|
||||
|
||||
// Keep the aim same when camera is moving
|
||||
let diff = camera_transform.translation - old;
|
||||
|
||||
if diff.length() > 0.0 {
|
||||
if let Some(t) = aim_target.0.as_mut() {
|
||||
*t += diff.xy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue