Reduce the distance the camera lags behind the player's actual position

This commit is contained in:
Thinkofname 2016-04-09 01:11:33 +01:00
parent e35a122305
commit 2acfa47491
3 changed files with 7 additions and 3 deletions

View File

@ -53,12 +53,14 @@ impl Position {
#[derive(Debug)]
pub struct TargetPosition {
pub position: Vector3<f64>,
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,
}
}

View File

@ -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);

View File

@ -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;
}
}