moria/src/camera.rs

21 lines
526 B
Rust
Raw Normal View History

2021-10-01 12:30:23 +00:00
use bevy::prelude::*;
use crate::player::*;
pub struct Camera;
pub fn camera_follow_player(
player: Query<(&Transform, &Player), Without<Camera>>,
mut camera: Query<(&mut Transform, &Camera), Without<Player>>,
) {
let player_pos = if let Some(player) = player.iter().next() {
player.0.translation
} else {
return;
};
for (mut trans, _) in camera.iter_mut() {
2021-10-01 22:44:53 +00:00
trans.translation = player_pos + Vec3::new(-50.0, 100.0, 50.0);
2021-10-01 12:30:23 +00:00
trans.look_at(player_pos, Vec3::Y);
}
}