fix: temporary marker will now not exist when character is unconscious

This commit is contained in:
Sara 2024-08-29 18:32:54 +02:00
parent 628d9bf923
commit 78baddfdfb

View file

@ -52,6 +52,10 @@ void Unit::stop_plan() {
}
void Unit::begin_marker_temporary(GoalMarker *marker) {
if(!this->get_entity_health()->is_conscious()) {
marker->queue_free();
return;
}
this->world_state->set_target_node(marker);
this->set_goal_and_plan(marker->get_goal());
// destroy temporary marker if goal is already achieved or failed
@ -61,6 +65,7 @@ void Unit::begin_marker_temporary(GoalMarker *marker) {
} else {
this->world_state->connect("attention_changed", callable_mp(marker, &GoalMarker::destroy_on_forgotten));
this->connect("goal_finished", callable_mp(marker, &GoalMarker::destroy_on_forgotten));
this->connect("plan_failed", callable_mp(marker, &GoalMarker::destroy_on_forgotten));
}
this->next_action();
}
@ -92,12 +97,14 @@ void Unit::aim_at(gd::Node3D *target) {
void Unit::on_unconscious(Unit *damage_source) {
this->destroy_state();
this->emit_signal("plan_failed");
this->anim_player->stop();
this->anim_player->play("death");
}
void Unit::on_death(Unit *damage_source) {
this->destroy_state();
this->emit_signal("plan_failed");
if(this->anim_player->get_current_animation() != gd::StringName("death")) {
this->anim_player->stop();
this->anim_player->play("death");