From 2acfa47491caee827d0a49f40461e261e38792d8 Mon Sep 17 00:00:00 2001 From: Thinkofname Date: Sat, 9 Apr 2016 01:11:33 +0100 Subject: [PATCH] Reduce the distance the camera lags behind the player's actual position --- src/entity/mod.rs | 2 ++ src/entity/player.rs | 4 +++- src/entity/systems.rs | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/entity/mod.rs b/src/entity/mod.rs index 352d4db..8dd5533 100644 --- a/src/entity/mod.rs +++ b/src/entity/mod.rs @@ -53,12 +53,14 @@ impl Position { #[derive(Debug)] pub struct TargetPosition { pub position: Vector3, + pub lerp_amount: f64, } impl TargetPosition { pub fn new(x: f64, y: f64, z: f64) -> TargetPosition { TargetPosition { position: Vector3::new(x, y, z), + lerp_amount: 0.2, } } diff --git a/src/entity/player.rs b/src/entity/player.rs index f46530c..06640d5 100644 --- a/src/entity/player.rs +++ b/src/entity/player.rs @@ -34,7 +34,9 @@ pub fn add_systems(m: &mut ecs::Manager) { pub fn create_local(m: &mut ecs::Manager) -> ecs::Entity { let entity = m.create_entity(); m.add_component_direct(entity, Position::new(0.0, 0.0, 0.0)); - m.add_component_direct(entity, TargetPosition::new(0.0, 0.0, 0.0)); + let mut tpos = TargetPosition::new(0.0, 0.0, 0.0); + tpos.lerp_amount = 1.0 / 3.0; + m.add_component_direct(entity, tpos); m.add_component_direct(entity, Rotation::new(0.0, 0.0)); m.add_component_direct(entity, Velocity::new(0.0, 0.0, 0.0)); m.add_component_direct(entity, Gamemode::Survival); diff --git a/src/entity/systems.rs b/src/entity/systems.rs index 8b4d70a..2b9cd5a 100644 --- a/src/entity/systems.rs +++ b/src/entity/systems.rs @@ -156,8 +156,8 @@ impl ecs::System for LerpPosition { let pos = m.get_component_mut(e, self.position).unwrap(); let target_pos = m.get_component(e, self.target_position).unwrap(); - pos.position = pos.position + (target_pos.position - pos.position) * delta * 0.2; - if (pos.position - target_pos.position).length2() < 0.01 { + pos.position = pos.position + (target_pos.position - pos.position) * delta * target_pos.lerp_amount; + if (pos.position - target_pos.position).length2() < 0.001 { pos.position = target_pos.position; } }