From ce0f54e9d646e834155a0caed9082e10fb89c93d Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 27 Mar 2020 22:19:23 -0400 Subject: [PATCH] Combine dir and force in KnockUp and ApplyForce events --- common/src/event.rs | 16 ++++------------ common/src/state.rs | 10 ++++++---- common/src/sys/combat.rs | 4 ++-- common/src/sys/projectile.rs | 4 ++-- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/common/src/event.rs b/common/src/event.rs index 809c607802..1575f31283 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -47,19 +47,11 @@ pub enum SfxEvent { pub enum LocalEvent { /// Applies upward force to entity's `Vel` Jump(EcsEntity), - /// Applies the `force` + implicit upward force, in `dir` direction to + /// Applies the `force` + implicit upward force to /// `entity`'s `Vel` - KnockUp { - entity: EcsEntity, - dir: Vec3, - force: f32, - }, - /// Applies the `force`, in `dir` direction to `entity`'s `Vel` - ApplyForce { - entity: EcsEntity, - dir: Vec3, - force: f32, - }, + KnockUp { entity: EcsEntity, force: Vec3 }, + /// Applies the `force` to `entity`'s `Vel` + ApplyForce { entity: EcsEntity, force: Vec3 }, /// Applies leaping force to `entity`'s `Vel` away from `wall_dir` direction WallLeap { entity: EcsEntity, diff --git a/common/src/state.rs b/common/src/state.rs index 4efc494917..91374f1a2f 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -355,15 +355,17 @@ impl State { vel.0.z = HUMANOID_JUMP_ACCEL; } }, - LocalEvent::KnockUp { entity, dir, force } => { + LocalEvent::KnockUp { entity, force } => { if let Some(vel) = velocities.get_mut(entity) { - vel.0 = dir * force; + vel.0 = force; vel.0.z = HUMANOID_JUMP_ACCEL; } }, - LocalEvent::ApplyForce { entity, dir, force } => { + LocalEvent::ApplyForce { entity, force } => { + // TODO: this sets the velocity directly to the value of `force`, consider + // renaming the event or changing the behavior if let Some(vel) = velocities.get_mut(entity) { - vel.0 = dir * force; + vel.0 = force; } }, LocalEvent::WallLeap { entity, wall_dir } => { diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index e8a7f207d2..5d7bbc69c0 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -141,8 +141,8 @@ impl<'a> System<'a> for Sys { if attack.knockback != 0.0 { local_emitter.emit(LocalEvent::ApplyForce { entity: b, - dir: *Dir::slerp(ori.0, Dir::new(Vec3::new(0.0, 0.0, 1.0)), 0.5), - force: attack.knockback, + force: attack.knockback + * *Dir::slerp(ori.0, Dir::new(Vec3::new(0.0, 0.0, 1.0)), 0.5), }); } attack.hit_count += 1; diff --git a/common/src/sys/projectile.rs b/common/src/sys/projectile.rs index 9841f1aaf9..0174f4299f 100644 --- a/common/src/sys/projectile.rs +++ b/common/src/sys/projectile.rs @@ -108,8 +108,8 @@ impl<'a> System<'a> for Sys { { local_emitter.emit(LocalEvent::ApplyForce { entity, - dir: *Dir::slerp(ori.0, Dir::new(Vec3::unit_z()), 0.5), - force: knockback, + force: knockback + * *Dir::slerp(ori.0, Dir::new(Vec3::unit_z()), 0.5), }); } },