generated from Persson-dev/Godot-Xmake
Bullets Colliding and Disappearing
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "Bullet.h"
|
||||
#include <godot_cpp/classes/timer.hpp>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
@@ -6,17 +7,40 @@ namespace blitz {
|
||||
|
||||
static constexpr float BULLET_SPEED = 40.0f;
|
||||
|
||||
void Bullet::_bind_methods() {}
|
||||
void Bullet::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_on_timer_timeout"), &Bullet::_on_timer_timeout);
|
||||
}
|
||||
|
||||
Bullet::Bullet() {}
|
||||
|
||||
Bullet::~Bullet() {}
|
||||
|
||||
void Bullet::_ready() {}
|
||||
void Bullet::_ready() {
|
||||
m_Particles = Object::cast_to<GPUParticles3D>(find_child("GPUParticles3D"));
|
||||
DEV_ASSERT(m_Particles);
|
||||
m_Ray = Object::cast_to<RayCast3D>(find_child("RayCast3D"));
|
||||
DEV_ASSERT(m_Ray);
|
||||
m_Mesh = Object::cast_to<MeshInstance3D>(find_child("MeshInstance3D"));
|
||||
DEV_ASSERT(m_Mesh);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void Bullet::_on_timer_timeout() {
|
||||
queue_free();
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user