add bullet decay

This commit is contained in:
2024-08-25 12:20:20 +02:00
parent 9df52e0016
commit b64a372af8
2 changed files with 17 additions and 1 deletions

View File

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

View File

@@ -1,6 +1,7 @@
#include <client/Bullet.h>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/geometry_instance3d.hpp>
#include <godot_cpp/classes/physics_direct_space_state3d.hpp>
#include <godot_cpp/classes/physics_ray_query_parameters3d.hpp>
#include <godot_cpp/classes/world3d.hpp>
@@ -32,6 +33,9 @@ void Bullet::_process(float a_Delta) {
return;
}
auto* head = get_node<Node3D>("Armature");
SetTransparency(head, m_LifeTime / MaxAlive);
if (m_Stuck)
return;
@@ -49,8 +53,18 @@ void Bullet::_process(float a_Delta) {
m_Stuck = true;
Vector3 intersectPoint = result["position"];
auto* head = get_node<Node3D>("Armature");
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<GeometryInstance3D>(a_Root);
if (mesh) {
mesh->set_transparency(a_Transparency);
}
}
} // namespace blitz