Add Dying animation

This commit is contained in:
Morph01
2024-08-22 17:53:25 +02:00
parent 1f52eb2c52
commit faf6a9116d
3 changed files with 828 additions and 110 deletions

View File

@@ -16,6 +16,7 @@ void Zombie::_bind_methods() {
ClassDB::bind_method(D_METHOD("hit_finished"), &Zombie::hit_finished);
ClassDB::bind_method(D_METHOD("_on_area_3d_a_zombie_head_shot_hit", "m_Health"), &Zombie::_on_area_3d_a_zombie_head_shot_hit);
ClassDB::bind_method(D_METHOD("_on_area_3d_a_zombie_body_shot_hit", "m_Health"), &Zombie::_on_area_3d_a_zombie_body_shot_hit);
ClassDB::bind_method(D_METHOD("_on_timer_timeout"), &Zombie::_on_timer_timeout);
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "m_PlayerPath"), "set_m_PlayerPath", "get_m_PlayerPath");
}
@@ -44,6 +45,9 @@ void Zombie::_ready() {
DEV_ASSERT(m_HeadCollision);
m_HeadCollision->connect("a_ZombieHeadShotHit", Callable(this, "_on_area_3d_a_zombie_head_shot_hit"));
connect_collision_shapes(m_BodyPartsCollision);
m_Timer = memnew(Timer);
add_child(m_Timer);
m_Timer->connect("timeout", callable_mp(this, &Zombie::_on_timer_timeout));
}
void Zombie::_process(float a_Delta) {
@@ -92,7 +96,10 @@ void Zombie::hit_finished() {
void Zombie::apply_damage(int dam) {
m_Health -= dam;
if (m_Health <= 0) {
queue_free();
m_AnimationTree->set("parameters/conditions/die", true);
this->set_velocity(Vector3(0, 0, 0));
m_Timer->set_wait_time(4.0);
m_Timer->start();
}
}
@@ -113,4 +120,8 @@ void Zombie::connect_collision_shapes(const std::vector<StringName>& body_parts)
}
}
void Zombie::_on_timer_timeout() {
queue_free();
}
} // namespace blitz