generated from Persson-dev/Godot-Xmake
Better Implementation of Timer
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#include "Bullet.h"
|
#include "Bullet.h"
|
||||||
#include <godot_cpp/classes/timer.hpp>
|
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
@@ -22,20 +21,20 @@ void Bullet::_ready() {
|
|||||||
DEV_ASSERT(m_Ray);
|
DEV_ASSERT(m_Ray);
|
||||||
m_Mesh = Object::cast_to<MeshInstance3D>(find_child("MeshInstance3D"));
|
m_Mesh = Object::cast_to<MeshInstance3D>(find_child("MeshInstance3D"));
|
||||||
DEV_ASSERT(m_Mesh);
|
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) {
|
void Bullet::_physics_process(float a_Delta) {
|
||||||
Vector3 movement = Vector3(0, 0, -BULLET_SPEED) * a_Delta;
|
Vector3 movement = Vector3(0, 0, -BULLET_SPEED) * a_Delta;
|
||||||
set_position(get_transform().xform(movement));
|
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()) {
|
if (m_Ray->is_colliding()) {
|
||||||
m_Mesh->set_visible(false);
|
m_Mesh->set_visible(false);
|
||||||
m_Particles->set_emitting(true);
|
m_Particles->set_emitting(true);
|
||||||
timer->set_wait_time(1.0);
|
m_Timer->set_wait_time(1.0);
|
||||||
timer->start();
|
m_Timer->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <godot_cpp/classes/mesh_instance3d.hpp>
|
#include <godot_cpp/classes/mesh_instance3d.hpp>
|
||||||
#include <godot_cpp/classes/node3d.hpp>
|
#include <godot_cpp/classes/node3d.hpp>
|
||||||
#include <godot_cpp/classes/ray_cast3d.hpp>
|
#include <godot_cpp/classes/ray_cast3d.hpp>
|
||||||
|
#include <godot_cpp/classes/timer.hpp>
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
class Bullet : public godot::Node3D {
|
class Bullet : public godot::Node3D {
|
||||||
@@ -22,6 +23,7 @@ class Bullet : public godot::Node3D {
|
|||||||
godot::GPUParticles3D* m_Particles;
|
godot::GPUParticles3D* m_Particles;
|
||||||
godot::RayCast3D* m_Ray;
|
godot::RayCast3D* m_Ray;
|
||||||
godot::MeshInstance3D* m_Mesh;
|
godot::MeshInstance3D* m_Mesh;
|
||||||
|
godot::Timer* m_Timer;
|
||||||
|
|
||||||
void _on_timer_timeout();
|
void _on_timer_timeout();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user