diff --git a/src/Bullet.cpp b/src/Bullet.cpp index f43823b..cc0c03f 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -1,5 +1,4 @@ #include "Bullet.h" -#include using namespace godot; @@ -22,20 +21,20 @@ void Bullet::_ready() { DEV_ASSERT(m_Ray); m_Mesh = Object::cast_to(find_child("MeshInstance3D")); DEV_ASSERT(m_Mesh); + m_Timer = memnew(godot::Timer); + add_child(m_Timer); + m_Timer->connect("timeout", callable_mp(this, &Bullet::_on_timer_timeout)); } void Bullet::_physics_process(float a_Delta) { Vector3 movement = Vector3(0, 0, -BULLET_SPEED) * a_Delta; set_position(get_transform().xform(movement)); - godot::Timer* timer = memnew(godot::Timer); - add_child(timer); - timer->connect("timeout", callable_mp(this, &Bullet::_on_timer_timeout)); if (m_Ray->is_colliding()) { m_Mesh->set_visible(false); m_Particles->set_emitting(true); - timer->set_wait_time(1.0); - timer->start(); + m_Timer->set_wait_time(1.0); + m_Timer->start(); } } diff --git a/src/Bullet.h b/src/Bullet.h index 063a308..cc668e7 100644 --- a/src/Bullet.h +++ b/src/Bullet.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace blitz { class Bullet : public godot::Node3D { @@ -22,6 +23,7 @@ class Bullet : public godot::Node3D { godot::GPUParticles3D* m_Particles; godot::RayCast3D* m_Ray; godot::MeshInstance3D* m_Mesh; + godot::Timer* m_Timer; void _on_timer_timeout(); };