Add cylinder bullet instead

This commit is contained in:
Sofia 2026-07-20 19:44:13 +03:00
parent 79f223cb21
commit 95e7c6ded4
2 changed files with 43 additions and 51 deletions

View File

@ -1,40 +1,18 @@
[gd_scene format=3 uid="uid://ctslratcr8h6v"]
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_3g557"]
particle_flag_align_y = true
radial_velocity_min = -500.0
radial_velocity_max = -500.0
scale_over_velocity_max = 1.0
[sub_resource type="Curve" id="Curve_dmbod"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_yxhor"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_k5804"]
emission_enabled = true
emission = Color(1, 0, 1, 1)
emission_energy_multiplier = 4.47
use_particle_trails = true
emission_energy_multiplier = 7.55
[sub_resource type="TubeTrailMesh" id="TubeTrailMesh_m77kh"]
material = SubResource("StandardMaterial3D_yxhor")
sections = 2
section_length = 0.5
section_rings = 5
cap_top = false
cap_bottom = false
curve = SubResource("Curve_dmbod")
[sub_resource type="CylinderMesh" id="CylinderMesh_1cgct"]
material = SubResource("StandardMaterial3D_k5804")
top_radius = 0.2
bottom_radius = 0.2
height = 1.0
[node name="raygun_bullet" type="Bullet" unique_id=1238833478 node_paths=PackedStringArray("emitter")]
emitter = NodePath("gpu_particles_3d")
[node name="raygun_bullet" type="Bullet" unique_id=1238833478]
[node name="gpu_particles_3d" type="GPUParticles3D" parent="." unique_id=1330763726]
emitting = false
amount = 1
lifetime = 3.8899999999999997
one_shot = true
fixed_fps = 100
trail_enabled = true
trail_lifetime = 0.5
process_material = SubResource("ParticleProcessMaterial_3g557")
draw_pass_1 = SubResource("TubeTrailMesh_m77kh")
[node name="mesh_instance_3d" type="MeshInstance3D" parent="." unique_id=1295653371]
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0)
mesh = SubResource("CylinderMesh_1cgct")

View File

@ -24,13 +24,15 @@ impl Weapon {
if let Some(prefab) = &self.bullet_prefab {
let mut bullet = prefab.instantiate_as::<Bullet>();
if let Some(mut parent) = self.base().find_parent("map") {
parent.add_child(&bullet);
if let Some(source) = &self.bullet_source {
bullet.set_global_position(source.get_global_position());
}
bullet.bind_mut().source = Some(source.get_global_position());
}
bullet.bind_mut().target = Some(to);
if let Some(mut parent) = self.base().find_parent("map") {
parent.add_child(&bullet);
}
}
}
}
@ -38,33 +40,45 @@ impl Weapon {
#[derive(GodotClass)]
#[class(base=Node3D, init)]
pub struct Bullet {
#[export]
pub emitter: Option<Gd<GpuParticles3D>>,
pub source: Option<Vector3>,
pub target: Option<Vector3>,
alive_for: f64,
distance: f32,
girth: f32,
base: Base<Node3D>,
}
#[godot_api]
impl INode3D for Bullet {
fn ready(&mut self) {
if let Some(emitter) = &mut self.emitter {
emitter.set_emitting(true);
if let (Some(target), Some(source)) = (self.target, self.source) {
let midway_point = (target + source) / 2.;
self.distance = source.distance_to(target);
self.girth = 1.;
self.scale();
self.base_mut().look_at_from_position(source, target);
self.base_mut().set_global_position(midway_point);
}
}
fn process(&mut self, delta: f64) {
self.alive_for += delta;
if self.alive_for > 0.05 {
let prev_pos = self.base().get_global_position();
if let Some(target) = self.target {
let new_pos = prev_pos.lerp(target, 0.5);
self.base_mut().set_position(new_pos);
fn process(&mut self, _delta: f32) {
self.girth = self.girth.lerp(0., 0.15);
self.scale();
}
}
impl Bullet {
fn scale(&mut self) {
let length = Vector3::BACK * self.distance;
let girth_scale = (Vector3::UP + Vector3::RIGHT) * self.girth;
self.base_mut().set_scale(length + girth_scale);
if self.girth < 0.05 {
self.base_mut().queue_free();
}
}
}