diff --git a/modules/wave_survival/player_body.cpp b/modules/wave_survival/player_body.cpp index 11394966..e7d03b7d 100644 --- a/modules/wave_survival/player_body.cpp +++ b/modules/wave_survival/player_body.cpp @@ -107,7 +107,7 @@ bool PlayerBody::get_is_running() const { } bool PlayerBody::get_wants_to_run() const { - return this->try_running && this->movement_input.y > 0.f && this->is_on_floor(); + return this->try_running && this->movement_input.y > 0.f; } HealthStatus *PlayerBody::get_health() const { diff --git a/modules/wave_survival/weapons/revolver.cpp b/modules/wave_survival/weapons/revolver.cpp index cdbde4a6..f541b515 100644 --- a/modules/wave_survival/weapons/revolver.cpp +++ b/modules/wave_survival/weapons/revolver.cpp @@ -1,6 +1,7 @@ #include "revolver.h" #include "scene/animation/animation_player.h" #include "wave_survival/macros.h" +#include "wave_survival/player_body.h" #include "wave_survival/player_camera.h" #include "wave_survival/player_input.h" @@ -10,33 +11,67 @@ void Revolver::_bind_methods() { BIND_PROPERTY(Variant::FLOAT, double_action_spread); } -void Revolver::play_equip_anim() { - get_anim()->play("equip", 0.0); - get_anim()->queue("idle_double"); - get_anim()->advance(0.0); -} - -void Revolver::shoot() { - if (!is_animating()) { - if (this->alt_active) { - get_anim()->queue("fire_single"); - this->alt_active = false; - this->muzzle->set_spread(this->single_action_spread); - this->muzzle->shoot(); - start_recoil(); - } else { - this->muzzle->set_spread(this->double_action_spread); - get_anim()->queue("fire_double"); - } +void Revolver::queue_idle_anim() { + if (get_anim()->get_current_animation() == "run") { + stop_running(); + } + // set a delay between the end of an action and (re)starting the run animation + this->run_animation_timer = this->run_animation_delay; + if (this->alt_active == true) { + get_anim()->queue("idle_single"); + } else { get_anim()->queue("idle_double"); } } +void Revolver::start_running() { + if (this->run_animation_timer <= 0.0) { + get_anim()->queue("run"); + } +} + +void Revolver::stop_running() { + String const current{ get_anim()->get_current_animation() }; + + if (current == "run") { + get_anim()->stop(); + } + if (current.begins_with("run")) { + if (this->alt_active) { + get_anim()->queue("run_to_single"); + } else { + get_anim()->queue("run_to_double"); + } + } +} + +void Revolver::play_equip_anim() { + get_anim()->play("equip", 0.0); + queue_idle_anim(); + get_anim()->advance(0.0); +} + +void Revolver::shoot() { + if (animation_is_idle()) { + stop_running(); + if (this->alt_active) { + this->alt_active = false; + this->muzzle->set_spread(this->single_action_spread); + get_anim()->queue("fire_single"); + } else { + this->muzzle->set_spread(this->double_action_spread); + get_anim()->queue("fire_double"); + } + queue_idle_anim(); + } +} + void Revolver::cock_hammer() { - if (!this->alt_active && !is_animating()) { + if (!this->alt_active && animation_is_idle()) { + stop_running(); this->alt_active = true; get_anim()->queue("to_single"); - get_anim()->queue("idle_single"); + queue_idle_anim(); } } @@ -67,6 +102,18 @@ void Revolver::process(double delta) { double t{ 1.0 - CLAMP(this->recoil_timer / this->recoil_time, 0.0, 1.0) }; get_camera()->recoil(Math::lerp((double)this->recoil_force, 0.0, t) * delta); } + if (this->run_animation_timer > 0.0) { + this->run_animation_timer -= delta; + } + if (!is_animating() && get_body()->get_is_running()) { + start_running(); + } else if (!get_body()->get_is_running() && get_anim()->get_current_animation() == "run") { + queue_idle_anim(); + } +} + +bool Revolver::animation_is_idle() const { + return !is_animating() || get_anim()->get_current_animation() == "run"; } void Revolver::_notification(int what) { diff --git a/modules/wave_survival/weapons/revolver.h b/modules/wave_survival/weapons/revolver.h index 96837191..fddbc2e6 100644 --- a/modules/wave_survival/weapons/revolver.h +++ b/modules/wave_survival/weapons/revolver.h @@ -7,6 +7,10 @@ class Revolver : public WeaponBase { GDCLASS(Revolver, WeaponBase); static void _bind_methods(); + void queue_idle_anim(); + void start_running(); + void stop_running(); + void interrupt_running(); void play_equip_anim(); void shoot(); void cock_hammer(); @@ -15,6 +19,8 @@ class Revolver : public WeaponBase { void ready(); void process(double delta); + bool animation_is_idle() const; + protected: void _notification(int what); virtual void notify_selected() override; @@ -34,8 +40,11 @@ private: HitscanMuzzle *muzzle{ nullptr }; float recoil_force{ 2.f }; - double recoil_time{ 0.06 }; + double recoil_time{ 0.1 }; double recoil_timer{ 0.0 }; + + double run_animation_delay{ 0.3 }; + double run_animation_timer{ 0.0 }; }; #endif // !WEAPONS_REVOLVER_H diff --git a/project/assets/animations/weapons/revolver/fire_single.res b/project/assets/animations/weapons/revolver/fire_single.res index 06941ab0..95b43885 100644 Binary files a/project/assets/animations/weapons/revolver/fire_single.res and b/project/assets/animations/weapons/revolver/fire_single.res differ diff --git a/project/assets/models/weapons/revolver.blend b/project/assets/models/weapons/revolver.blend index 20ba1ca0..7cb825cb 100644 Binary files a/project/assets/models/weapons/revolver.blend and b/project/assets/models/weapons/revolver.blend differ diff --git a/project/assets/models/weapons/revolver.blend1 b/project/assets/models/weapons/revolver.blend1 index ba75f7fe..27b723dc 100644 Binary files a/project/assets/models/weapons/revolver.blend1 and b/project/assets/models/weapons/revolver.blend1 differ diff --git a/project/objects/weapons/revolver.tscn b/project/objects/weapons/revolver.tscn index 7262dc90..83a825b9 100644 --- a/project/objects/weapons/revolver.tscn +++ b/project/objects/weapons/revolver.tscn @@ -16,6 +16,36 @@ double_action_spread = 0.02 [node name="revolver" parent="." instance=ExtResource("1_5ynga")] +[node name="Skeleton3D" parent="revolver/Character" index="0"] +bones/1/position = Vector3(0.077683, 0.15356629, 0.22951864) +bones/1/rotation = Quaternion(0.5851843, 0.4764963, 0.47324383, -0.45447868) +bones/2/rotation = Quaternion(-0.37339994, -0.012608625, 0.4248388, 0.8245759) +bones/3/rotation = Quaternion(0.13469099, 0.084066905, 0.5777786, 0.8006018) +bones/4/rotation = Quaternion(0.2787549, 0.10335517, 0.061925787, 0.9527742) +bones/5/rotation = Quaternion(-0.16385715, 0.07371643, -0.117167264, 0.9767234) +bones/6/rotation = Quaternion(-0.10018807, 0.001737441, -0.017251449, 0.99481744) +bones/7/rotation = Quaternion(-5.5135492e-06, -8.1514554e-07, -0.000472692, 0.9999999) +bones/8/rotation = Quaternion(-0.67974395, 0.15276042, 0.07346374, 0.7135934) +bones/9/rotation = Quaternion(-0.52413255, -0.0052551557, 0.008540811, 0.85157764) +bones/10/rotation = Quaternion(-0.45302963, 0.0016381529, -0.0032266718, 0.89148813) +bones/11/rotation = Quaternion(-0.6447599, 0.17695156, 0.030249279, 0.74300593) +bones/12/rotation = Quaternion(-0.61815894, -0.0058423695, 0.008146204, 0.78598917) +bones/13/rotation = Quaternion(-0.28957173, 0.0008908786, -0.0035062442, 0.95714945) +bones/14/rotation = Quaternion(-0.4137267, 0.18337816, -0.055713132, 0.88999933) +bones/15/rotation = Quaternion(-0.56248397, 0.008516232, 0.01857911, 0.82655555) +bones/16/rotation = Quaternion(-0.5171131, -0.003298891, -0.013025877, 0.8558117) +bones/17/position = Vector3(-0.035217345, 0.031610142, 0.010926659) +bones/17/rotation = Quaternion(-0.23086587, 0.40491727, 0.5210391, 0.7150253) +bones/18/rotation = Quaternion(-0.027613077, -0.014708879, 0.040168725, 0.998703) +bones/19/rotation = Quaternion(0.008477317, 0.0136856465, -0.3318223, 0.9432046) +bones/20/rotation = Quaternion(0.5851843, -0.4764963, -0.47324383, -0.45447868) +bones/39/position = Vector3(0.09835215, -0.26794472, -0.3457696) +bones/39/rotation = Quaternion(0.24137872, 3.1304803e-18, 1.1981784e-16, 0.9704311) +bones/40/position = Vector3(0.015597563, 0.030223738, 0.0061558606) +bones/40/rotation = Quaternion(-0.5071953, 0.4361461, -0.43880603, 0.5999824) +bones/43/rotation = Quaternion(0.16942807, 1.17632844e-07, -1.932268e-08, 0.98554254) +bones/44/rotation = Quaternion(0.9970487, -9.152002e-09, 1.18857486e-07, -0.0767723) + [node name="Body" parent="revolver/Character/Skeleton3D" index="0"] layers = 2 @@ -23,7 +53,7 @@ layers = 2 layers = 2 [node name="BoneAttachment3D" type="BoneAttachment3D" parent="revolver/Character/Skeleton3D" index="2"] -transform = Transform3D(1, -6.350722e-17, 4.732016e-17, 4.732016e-17, 0.95822614, 0.28601173, -6.350722e-17, -0.28601173, 0.95822614, -1.1196792e-16, -0.03667751, 0.009908612) +transform = Transform3D(1, -2.3103859e-16, 6.391877e-17, 2.3406112e-16, 0.8834727, -0.46848273, 5.176711e-17, 0.46848273, 0.8834727, 0.09835215, -0.26794472, -0.3457696) bone_name = "root" bone_idx = 39