From 2ea1de26590e59591a27bfd887bfbd4d40b4064c Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 16 Apr 2019 20:20:36 +0100 Subject: [PATCH] Added smooth acceleration Former-commit-id: 4dfc695e5d1485b77ef98b1f5895d3eee69c46e1 --- client/src/lib.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 04b159ff30..4a4dc91de1 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -149,17 +149,15 @@ impl Client { }); // Step 1 - if - self.state.read_storage::().get(self.player).is_some() && - self.state.read_storage::().get(self.player).is_some() && - self.state.read_storage::().get(self.player).is_some() - { - // TODO: remove this - const PLAYER_VELOCITY: f32 = 100.0; - // TODO: Set acceleration instead - self.state.write_component(self.player, comp::phys::Vel(Vec3::from(input.move_dir * PLAYER_VELOCITY) * 0.1)); + if let (Some(_), Some(vel), Some(_)) = ( + self.state.read_component_cloned::(self.player), + self.state.read_component_cloned::(self.player), + self.state.read_component_cloned::(self.player), + ) { + self.state.write_component(self.player, comp::phys::Vel(vel.0 + input.move_dir * 2.0 - vel.0.map(|e| e * e.abs() + e) * 0.03)); + if input.move_dir.magnitude() > 0.01 { - self.state.write_component(self.player, comp::phys::Dir(input.move_dir.normalized().into())); + self.state.write_component(self.player, comp::phys::Dir(vel.0.normalized() * Vec3::new(1.0, 1.0, 0.0))); self.state.write_component(self.player, comp::Animation::Run); } else { self.state.write_component(self.player, comp::Animation::Idle);