bullet: remove transparency

This commit is contained in:
2024-08-27 15:01:14 +02:00
parent e5436241ef
commit 60d0a83345
2 changed files with 11 additions and 19 deletions

View File

@@ -18,9 +18,8 @@ class Bullet : public godot::Node3D {
private: private:
bool m_Stuck; bool m_Stuck;
float m_LifeTime;
void SetTransparency(godot::Node* a_Root, float a_Transparency); void Destroy();
}; };
} // namespace blitz } // namespace blitz

View File

@@ -4,6 +4,7 @@
#include <godot_cpp/classes/geometry_instance3d.hpp> #include <godot_cpp/classes/geometry_instance3d.hpp>
#include <godot_cpp/classes/physics_direct_space_state3d.hpp> #include <godot_cpp/classes/physics_direct_space_state3d.hpp>
#include <godot_cpp/classes/physics_ray_query_parameters3d.hpp> #include <godot_cpp/classes/physics_ray_query_parameters3d.hpp>
#include <godot_cpp/classes/timer.hpp>
#include <godot_cpp/classes/world3d.hpp> #include <godot_cpp/classes/world3d.hpp>
#include <godot_cpp/variant/utility_functions.hpp> #include <godot_cpp/variant/utility_functions.hpp>
@@ -18,7 +19,13 @@ void Bullet::_bind_methods() {}
Bullet::Bullet() : m_Stuck(false) {} 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() {} Bullet::~Bullet() {}
@@ -27,14 +34,7 @@ void Bullet::_process(float a_Delta) {
return; return;
} }
m_LifeTime += a_Delta;
if (m_LifeTime > MaxAlive) {
queue_free();
return;
}
auto* head = get_node<Node3D>("Armature"); auto* head = get_node<Node3D>("Armature");
SetTransparency(head, m_LifeTime / MaxAlive);
if (m_Stuck) if (m_Stuck)
return; return;
@@ -56,15 +56,8 @@ void Bullet::_process(float a_Delta) {
head->set_global_position(intersectPoint); head->set_global_position(intersectPoint);
} }
void Bullet::SetTransparency(Node* a_Root, float a_Transparency) { void Bullet::Destroy() {
for (int i = 0; i < a_Root->get_child_count(); i++) { queue_free();
SetTransparency(a_Root->get_child(i), a_Transparency);
}
GeometryInstance3D* mesh = Object::cast_to<GeometryInstance3D>(a_Root);
if (mesh) {
mesh->set_transparency(a_Transparency);
}
} }
} // namespace blitz } // namespace blitz