generated from Persson-dev/Godot-Xmake
Bullets Colliding and Disappearing
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=3 format=3 uid="uid://do601jl7p1u22"]
|
[gd_scene load_steps=6 format=3 uid="uid://do601jl7p1u22"]
|
||||||
|
|
||||||
[sub_resource type="BoxMesh" id="BoxMesh_ibwn0"]
|
[sub_resource type="BoxMesh" id="BoxMesh_ibwn0"]
|
||||||
size = Vector3(0.05, 0.05, 1)
|
size = Vector3(0.05, 0.05, 1)
|
||||||
@@ -9,7 +9,23 @@ emission_enabled = true
|
|||||||
emission = Color(0.568627, 1, 0.313726, 1)
|
emission = Color(0.568627, 1, 0.313726, 1)
|
||||||
emission_energy_multiplier = 5.0
|
emission_energy_multiplier = 5.0
|
||||||
|
|
||||||
|
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_618v8"]
|
||||||
|
direction = Vector3(0, 0, 1)
|
||||||
|
initial_velocity_min = 3.0
|
||||||
|
initial_velocity_max = 5.0
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gn2fy"]
|
||||||
|
albedo_color = Color(1, 1, 0.443137, 1)
|
||||||
|
emission_enabled = true
|
||||||
|
emission = Color(0.568627, 1, 0.313726, 1)
|
||||||
|
emission_energy_multiplier = 8.0
|
||||||
|
|
||||||
|
[sub_resource type="BoxMesh" id="BoxMesh_5un5e"]
|
||||||
|
material = SubResource("StandardMaterial3D_gn2fy")
|
||||||
|
size = Vector3(0.04, 0.04, 0.04)
|
||||||
|
|
||||||
[node name="Bullet" type="Bullet"]
|
[node name="Bullet" type="Bullet"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -52730.2)
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
mesh = SubResource("BoxMesh_ibwn0")
|
mesh = SubResource("BoxMesh_ibwn0")
|
||||||
@@ -17,3 +33,19 @@ surface_material_override/0 = SubResource("StandardMaterial3D_2qdhl")
|
|||||||
|
|
||||||
[node name="RayCast3D" type="RayCast3D" parent="."]
|
[node name="RayCast3D" type="RayCast3D" parent="."]
|
||||||
target_position = Vector3(0, 0, -0.6)
|
target_position = Vector3(0, 0, -0.6)
|
||||||
|
|
||||||
|
[node name="GPUParticles3D" type="GPUParticles3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.7)
|
||||||
|
emitting = false
|
||||||
|
one_shot = true
|
||||||
|
explosiveness = 1.0
|
||||||
|
visibility_aabb = AABB(-1.00001, -6.06334, -1.00001, 2.00002, 7.06267, 41.4102)
|
||||||
|
process_material = SubResource("ParticleProcessMaterial_618v8")
|
||||||
|
draw_pass_1 = SubResource("BoxMesh_5un5e")
|
||||||
|
|
||||||
|
[node name="Timer" type="Timer" parent="."]
|
||||||
|
wait_time = 10.0
|
||||||
|
one_shot = true
|
||||||
|
autostart = true
|
||||||
|
|
||||||
|
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "Bullet.h"
|
#include "Bullet.h"
|
||||||
|
#include <godot_cpp/classes/timer.hpp>
|
||||||
|
|
||||||
using namespace godot;
|
using namespace godot;
|
||||||
|
|
||||||
@@ -6,17 +7,40 @@ namespace blitz {
|
|||||||
|
|
||||||
static constexpr float BULLET_SPEED = 40.0f;
|
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() {}
|
||||||
|
|
||||||
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) {
|
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()) {
|
||||||
|
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
|
} // namespace blitz
|
||||||
10
src/Bullet.h
10
src/Bullet.h
@@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <godot_cpp/classes/gpu_particles3d.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>
|
||||||
|
|
||||||
namespace blitz {
|
namespace blitz {
|
||||||
class Bullet : public godot::Node3D {
|
class Bullet : public godot::Node3D {
|
||||||
@@ -14,6 +17,13 @@ class Bullet : public godot::Node3D {
|
|||||||
|
|
||||||
void _ready();
|
void _ready();
|
||||||
void _physics_process(float delta);
|
void _physics_process(float delta);
|
||||||
|
|
||||||
|
private:
|
||||||
|
godot::GPUParticles3D* m_Particles;
|
||||||
|
godot::RayCast3D* m_Ray;
|
||||||
|
godot::MeshInstance3D* m_Mesh;
|
||||||
|
|
||||||
|
void _on_timer_timeout();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blitz
|
} // namespace blitz
|
||||||
Reference in New Issue
Block a user