Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Particle Effect on Enemy Destruction #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions objects/enemy.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extends Node3D

@export var player:Node3D
@export var explosion:PackedScene = preload("res://objects/explosion.tscn")

@onready var raycast = $RayCast
@onready var muzzle_a = $MuzzleA
Expand Down Expand Up @@ -42,6 +43,9 @@ func damage(amount):
func destroy():

Audio.play("sounds/enemy_destroy.ogg")
var effects = explosion.instantiate()
effects.transform = transform
get_parent().add_child(effects)

destroyed = true
queue_free()
Expand Down
52 changes: 52 additions & 0 deletions objects/explosion.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[gd_scene load_steps=8 format=3 uid="uid://b12upspnoxxag"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_7mj45"]
transparency = 1
vertex_color_use_as_albedo = true

[sub_resource type="Gradient" id="Gradient_5nod5"]
offsets = PackedFloat32Array(0, 0.5, 1)
colors = PackedColorArray(0, 0, 0, 1, 0.3, 0.15, 0.15, 1, 0.6, 0.6, 0.6, 1)

[sub_resource type="GradientTexture1D" id="GradientTexture1D_fr1au"]
gradient = SubResource("Gradient_5nod5")

[sub_resource type="Gradient" id="Gradient_i8smv"]
offsets = PackedFloat32Array(0, 0.8, 1)
colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)

[sub_resource type="GradientTexture1D" id="GradientTexture1D_861rp"]
gradient = SubResource("Gradient_i8smv")

[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_mmndt"]
lifetime_randomness = 0.25
emission_shape = 1
emission_sphere_radius = 0.25
direction = Vector3(0, 1, 0)
spread = 35.0
initial_velocity_min = 1.0
initial_velocity_max = 4.0
scale_min = 0.8
color_ramp = SubResource("GradientTexture1D_861rp")
color_initial_ramp = SubResource("GradientTexture1D_fr1au")

[sub_resource type="BoxMesh" id="BoxMesh_oe02q"]
size = Vector3(0.1, 0.1, 0.1)

[node name="explosion" type="Node3D"]

[node name="GPUParticles3D" type="GPUParticles3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.25, 0)
material_override = SubResource("StandardMaterial3D_7mj45")
amount = 64
lifetime = 0.8
one_shot = true
explosiveness = 1.0
process_material = SubResource("ParticleProcessMaterial_mmndt")
draw_pass_1 = SubResource("BoxMesh_oe02q")

[node name="Timer" type="Timer" parent="."]
one_shot = true
autostart = true

[connection signal="timeout" from="Timer" to="." method="queue_free"]