add particle hit effect
This commit is contained in:
18
scripts/effects/particles_3d_self_destructing.gd
Normal file
18
scripts/effects/particles_3d_self_destructing.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
class_name Particles3DSelfDestructing extends GPUParticles3D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
emitting = true
|
||||
for node in get_children():
|
||||
if node is GPUParticles3D:
|
||||
(node as GPUParticles3D).emitting = true
|
||||
finished.connect(_on_finished)
|
||||
|
||||
|
||||
func init(start_position: Vector3, direction: Vector3 = Vector3.ZERO) -> void:
|
||||
global_position = start_position
|
||||
look_at(global_position + direction)
|
||||
|
||||
|
||||
func _on_finished() -> void:
|
||||
queue_free()
|
||||
1
scripts/effects/particles_3d_self_destructing.gd.uid
Normal file
1
scripts/effects/particles_3d_self_destructing.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://x3uft3uwakct
|
||||
@@ -134,7 +134,7 @@ func _hit_projectile(projectile: Projectile) -> void:
|
||||
projectile.global_position,
|
||||
projectile.global_position + new_direction
|
||||
)
|
||||
projectile.set_velocity(new_direction * _hit_projectile_speed)
|
||||
projectile.hit(new_direction * _hit_projectile_speed)
|
||||
break
|
||||
|
||||
prev_dir_angle = dir_angle
|
||||
|
||||
@@ -7,6 +7,7 @@ const MAX_STRETCH: float = 0.75
|
||||
@export var _speed_stretch_factor: float = 100
|
||||
|
||||
@export var _collision_debug_material: Material
|
||||
@export var _hit_particles_scene: PackedScene
|
||||
|
||||
var _start_position: Vector3
|
||||
var _velocity: Vector3
|
||||
@@ -52,6 +53,15 @@ func init(velocity: Vector3, start_position: Vector3, lifetime: float = 10) -> v
|
||||
_lifetime = lifetime
|
||||
|
||||
|
||||
func hit(velocity: Vector3) -> void:
|
||||
var hit_particles := (
|
||||
_hit_particles_scene.instantiate() as Particles3DSelfDestructing
|
||||
)
|
||||
get_tree().get_root().add_child(hit_particles)
|
||||
hit_particles.init(global_position, velocity)
|
||||
set_velocity(velocity)
|
||||
|
||||
|
||||
func set_velocity(velocity: Vector3) -> void:
|
||||
_velocity = velocity
|
||||
_life_timer = _lifetime
|
||||
|
||||
Reference in New Issue
Block a user