Add cylinder bullet instead
This commit is contained in:
parent
79f223cb21
commit
95e7c6ded4
@ -1,40 +1,18 @@
|
|||||||
[gd_scene format=3 uid="uid://ctslratcr8h6v"]
|
[gd_scene format=3 uid="uid://ctslratcr8h6v"]
|
||||||
|
|
||||||
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_3g557"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_k5804"]
|
||||||
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"]
|
|
||||||
emission_enabled = true
|
emission_enabled = true
|
||||||
emission = Color(1, 0, 1, 1)
|
emission = Color(1, 0, 1, 1)
|
||||||
emission_energy_multiplier = 4.47
|
emission_energy_multiplier = 7.55
|
||||||
use_particle_trails = true
|
|
||||||
|
|
||||||
[sub_resource type="TubeTrailMesh" id="TubeTrailMesh_m77kh"]
|
[sub_resource type="CylinderMesh" id="CylinderMesh_1cgct"]
|
||||||
material = SubResource("StandardMaterial3D_yxhor")
|
material = SubResource("StandardMaterial3D_k5804")
|
||||||
sections = 2
|
top_radius = 0.2
|
||||||
section_length = 0.5
|
bottom_radius = 0.2
|
||||||
section_rings = 5
|
height = 1.0
|
||||||
cap_top = false
|
|
||||||
cap_bottom = false
|
|
||||||
curve = SubResource("Curve_dmbod")
|
|
||||||
|
|
||||||
[node name="raygun_bullet" type="Bullet" unique_id=1238833478 node_paths=PackedStringArray("emitter")]
|
[node name="raygun_bullet" type="Bullet" unique_id=1238833478]
|
||||||
emitter = NodePath("gpu_particles_3d")
|
|
||||||
|
|
||||||
[node name="gpu_particles_3d" type="GPUParticles3D" parent="." unique_id=1330763726]
|
[node name="mesh_instance_3d" type="MeshInstance3D" parent="." unique_id=1295653371]
|
||||||
emitting = false
|
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0)
|
||||||
amount = 1
|
mesh = SubResource("CylinderMesh_1cgct")
|
||||||
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")
|
|
||||||
|
|||||||
@ -24,13 +24,15 @@ impl Weapon {
|
|||||||
|
|
||||||
if let Some(prefab) = &self.bullet_prefab {
|
if let Some(prefab) = &self.bullet_prefab {
|
||||||
let mut bullet = prefab.instantiate_as::<Bullet>();
|
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 {
|
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);
|
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)]
|
#[derive(GodotClass)]
|
||||||
#[class(base=Node3D, init)]
|
#[class(base=Node3D, init)]
|
||||||
pub struct Bullet {
|
pub struct Bullet {
|
||||||
#[export]
|
pub source: Option<Vector3>,
|
||||||
pub emitter: Option<Gd<GpuParticles3D>>,
|
|
||||||
|
|
||||||
pub target: Option<Vector3>,
|
pub target: Option<Vector3>,
|
||||||
|
|
||||||
alive_for: f64,
|
alive_for: f64,
|
||||||
|
|
||||||
|
distance: f32,
|
||||||
|
girth: f32,
|
||||||
|
|
||||||
base: Base<Node3D>,
|
base: Base<Node3D>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[godot_api]
|
#[godot_api]
|
||||||
impl INode3D for Bullet {
|
impl INode3D for Bullet {
|
||||||
fn ready(&mut self) {
|
fn ready(&mut self) {
|
||||||
if let Some(emitter) = &mut self.emitter {
|
if let (Some(target), Some(source)) = (self.target, self.source) {
|
||||||
emitter.set_emitting(true);
|
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) {
|
fn process(&mut self, _delta: f32) {
|
||||||
self.alive_for += delta;
|
self.girth = self.girth.lerp(0., 0.15);
|
||||||
if self.alive_for > 0.05 {
|
self.scale();
|
||||||
let prev_pos = self.base().get_global_position();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(target) = self.target {
|
impl Bullet {
|
||||||
let new_pos = prev_pos.lerp(target, 0.5);
|
fn scale(&mut self) {
|
||||||
self.base_mut().set_position(new_pos);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user