diff --git a/src/rts_states.cpp b/src/rts_states.cpp index 2987385..1ac95ce 100644 --- a/src/rts_states.cpp +++ b/src/rts_states.cpp @@ -72,13 +72,26 @@ double MoveTo::get_repath_interval() const { void Activate::_bind_methods() {} +void Activate::_ready() { + this->anim = this->get_parent()->get_node("%AnimationPlayer"); + if(!this->anim->has_animation(this->animation)) + this->end_state(); + else this->anim->play(this->animation); +} + +void Activate::_process(double) { + bool const animation_finished{!this->anim->is_playing() || this->anim->get_current_animation() != this->animation}; + if(this->is_action_done_interrupt() || animation_finished) + this->end_state(); +} + void Animate::_bind_methods() {} void Animate::_ready() { - this->anim = this->get_node("../AnimationPlayer"); - this->anim->play(this->animation); + this->anim = this->get_parent()->get_node("%AnimationPlayer"); if(!this->anim->has_animation(this->animation)) this->end_state(); + else this->anim->play(this->animation); } void Animate::_process(double) { diff --git a/src/rts_states.hpp b/src/rts_states.hpp index b1f444a..48049f6 100644 --- a/src/rts_states.hpp +++ b/src/rts_states.hpp @@ -34,8 +34,12 @@ class Activate : public goap::State { GDCLASS(Activate, goap::State); static void _bind_methods(); public: + virtual void _ready() override; + virtual void _process(double) override; gd::Node3D *target_node{nullptr}; gd::String animation{}; +private: + gd::AnimationPlayer *anim{nullptr}; }; class Animate : public goap::State {