diff --git a/src/unit.cpp b/src/unit.cpp index de82998..ecfad33 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -19,7 +19,7 @@ void Unit::_enter_tree() { GDGAMEONLY(); this->world_state = this->get_node("ActorWorldState"); this->eyes = this->get_node("%Eyes"); this->world_state->connect("attention_changed", callable_mp(this, &Unit::stop_plan)); - + this->anim_player = this->get_node("AnimationPlayer"); EntityHealth *health{this->get_node("EntityHealth")}; health->connect("death", callable_mp(this, &Unit::on_death)); } @@ -77,8 +77,9 @@ void Unit::aim_at(gd::Node3D *target) { this->set_global_basis({x, z.cross(x), z}); } -void Unit::on_death(Unit *killer) { - this->queue_free(); +void Unit::on_death(Unit *damage_source) { + this->anim_player->stop(); + this->anim_player->play("death"); } UnitWorldState *Unit::get_world_state() const { diff --git a/src/unit.hpp b/src/unit.hpp index 5d43bb3..524aa85 100644 --- a/src/unit.hpp +++ b/src/unit.hpp @@ -6,6 +6,7 @@ #include "goap/goal.hpp" #include "goap/planner.hpp" #include "utils/godot_macros.hpp" +#include #include #include #include @@ -33,7 +34,7 @@ public: void fire_at_target(); void aim_at(gd::Node3D *node); - void on_death(Unit *killer); + void on_death(Unit *damage_source); UnitWorldState *get_world_state() const; gd::Transform3D get_eye_transform() const; @@ -60,8 +61,9 @@ private: UnitTeam team{UnitTeam::Neutral}; gd::NavigationAgent3D *agent{nullptr}; - UnitWorldState *world_state{nullptr}; + gd::AnimationPlayer *anim_player{nullptr}; goap::Planner *planner{nullptr}; + UnitWorldState *world_state{nullptr}; }; #endif // !RTS_UNIT_HPP