diff --git a/include/client/Bullet.h b/include/client/Bullet.h index c65304e..f737eea 100644 --- a/include/client/Bullet.h +++ b/include/client/Bullet.h @@ -18,9 +18,8 @@ class Bullet : public godot::Node3D { private: bool m_Stuck; - float m_LifeTime; - void SetTransparency(godot::Node* a_Root, float a_Transparency); + void Destroy(); }; } // namespace blitz \ No newline at end of file diff --git a/src/client/Bullet.cpp b/src/client/Bullet.cpp index c61c0aa..331ee76 100644 --- a/src/client/Bullet.cpp +++ b/src/client/Bullet.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -18,7 +19,13 @@ void Bullet::_bind_methods() {} Bullet::Bullet() : m_Stuck(false) {} -void Bullet::_ready() {} +void Bullet::_ready() { + Timer* timer = memnew(Timer); + add_child(timer); + timer->connect("timeout", callable_mp(this, &Bullet::Destroy)); + timer->set_wait_time(MaxAlive); + timer->start(); +} Bullet::~Bullet() {} @@ -27,14 +34,7 @@ void Bullet::_process(float a_Delta) { return; } - m_LifeTime += a_Delta; - if (m_LifeTime > MaxAlive) { - queue_free(); - return; - } - auto* head = get_node("Armature"); - SetTransparency(head, m_LifeTime / MaxAlive); if (m_Stuck) return; @@ -56,15 +56,8 @@ void Bullet::_process(float a_Delta) { head->set_global_position(intersectPoint); } -void Bullet::SetTransparency(Node* a_Root, float a_Transparency) { - for (int i = 0; i < a_Root->get_child_count(); i++) { - SetTransparency(a_Root->get_child(i), a_Transparency); - } - - GeometryInstance3D* mesh = Object::cast_to(a_Root); - if (mesh) { - mesh->set_transparency(a_Transparency); - } +void Bullet::Destroy() { + queue_free(); } } // namespace blitz \ No newline at end of file