change camera movement

main
annieversary 2021-10-02 00:44:53 +02:00
parent 6b2075c2a4
commit 9a0c360172
2 changed files with 2 additions and 19 deletions

View File

@ -6,7 +6,6 @@ pub struct Camera;
pub fn camera_follow_player(
player: Query<(&Transform, &Player), Without<Camera>>,
mut camera: Query<(&mut Transform, &Camera), Without<Player>>,
time: Res<Time>,
) {
let player_pos = if let Some(player) = player.iter().next() {
player.0.translation
@ -14,21 +13,8 @@ pub fn camera_follow_player(
return;
};
let ds = time.delta_seconds() * 5.0;
// TODO Change this to normal movement
for (mut trans, _) in camera.iter_mut() {
trans.translation = player_pos + Vec3::new(-50.0, 100.0, 50.0);
trans.look_at(player_pos, Vec3::Y);
// keep a distance to the player
if trans.translation.distance(player_pos) > 170.0 {
let mut d = trans.rotation * Vec3::Z * ds;
d.y = 0.0;
trans.translation -= d;
}
if trans.translation.distance(player_pos) < 130.0 {
let mut d = trans.rotation * Vec3::Z * ds;
d.y = 0.0;
trans.translation += d;
}
}
}

View File

@ -97,9 +97,6 @@ fn setup(
// camera
commands
.spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_xyz(-40.0, 110.0, 40.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
})
.spawn_bundle(PerspectiveCameraBundle::default())
.insert(Camera);
}