🐛 Fix explosion bugs and cleanup logic

This commit is contained in:
Squinternator 2024-04-11 17:44:13 +00:00
parent 7a8f0c91a1
commit 91f14aea21
6 changed files with 22 additions and 25 deletions

View file

@ -24,7 +24,6 @@ func explode(spawn_location):
var spawned_explosion = EXPLOSION.instantiate()
spawned_explosion.position = spawn_location
game.add_child(spawned_explosion)
spawned_explosion.explode()
queue_free()
func _physics_process(delta):

View file

@ -1,24 +1,22 @@
extends Node3D
@onready var fire = $Fire
@onready var explosion_area : AreaDamageComponent = $AreaDamageComponent
@onready var area_damage : AreaDamageComponent = $AreaDamageComponent
var explosion_effect_pending : bool = false
const impulse_force = 1000;
func explode():
explosion_effect_pending = true
func _ready():
fire.emitting = true
func _physics_process(_delta):
if explosion_effect_pending:
var bodies = explosion_area.get_overlapping_bodies()
var bodies = area_damage.get_overlapping_bodies()
for body in bodies:
if body is RigidBody3D:
var direction = (body.global_position - global_position).normalized()
body.apply_central_impulse(direction * impulse_force)
for body in bodies:
if body is RigidBody3D:
var direction = (body.global_position - global_position).normalized()
body.apply_central_impulse(direction * impulse_force)
explosion_effect_pending = false
await get_tree().create_timer(1.0).timeout
queue_free()
area_damage.monitorable = false
area_damage.monitoring = false
await get_tree().create_timer(1.0).timeout
queue_free()

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://8atq41j7wd55"]
[gd_scene load_steps=9 format=3 uid="uid://8atq41j7wd55"]
[ext_resource type="Script" path="res://weapons/space_gun/projectile_explosion.gd" id="1_fp5td"]
[ext_resource type="PackedScene" uid="uid://ds1hekx1dq1bg" path="res://components/area_damage_component.tscn" id="2_reyvo"]
@ -25,6 +25,9 @@ emission_energy_multiplier = 4.0
[sub_resource type="SphereMesh" id="SphereMesh_k3pnh"]
material = SubResource("StandardMaterial3D_wpu51")
[sub_resource type="SphereShape3D" id="SphereShape3D_mlo2k"]
radius = 5.0
[node name="ProjectileExplosion" type="Node3D"]
script = ExtResource("1_fp5td")
@ -40,3 +43,6 @@ draw_pass_1 = SubResource("SphereMesh_k3pnh")
[node name="AreaDamageComponent" parent="." instance=ExtResource("2_reyvo")]
damage = 35
[node name="CollisionShape3D" type="CollisionShape3D" parent="AreaDamageComponent"]
shape = SubResource("SphereShape3D_mlo2k")