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

Spawn on Death Array + NPC corpse #289

Merged
merged 1 commit into from
Sep 24, 2024
Merged
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
13 changes: 7 additions & 6 deletions COGITO/Components/Attributes/cogito_health_attribute.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ signal death()
@export var sound_on_death : AudioStream
## Nodepaths to nodes that get destroyed on death.
@export var destroy_on_death : Array[NodePath]
## PackedScene that will get spawned on parent position on death.
@export var spawn_on_death : PackedScene
## Array of Scenes that will get spawned on parent position on death.
@export var spawn_on_death : Array[PackedScene] = []

var parent_position : Vector3

Expand All @@ -41,10 +41,11 @@ func on_death(_attribute_name:String, _value_current:float, _value_max:float):
if sound_on_death:
Audio.play_sound_3d(sound_on_death).position = parent_position

if spawn_on_death:
var spawned_object = spawn_on_death.instantiate()
spawned_object.position = parent_position
get_tree().current_scene.add_child(spawned_object)
for scene in spawn_on_death:
if scene:
var spawned_object = scene.instantiate()
spawned_object.position = parent_position
get_tree().current_scene.add_child(spawned_object)

for nodepath in destroy_on_death:
if get_node(nodepath):
Expand Down
2 changes: 1 addition & 1 deletion COGITO/DemoScenes/DemoPrefabs/barrel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ health_attribute = NodePath("../HealthAttribute")

[node name="HealthAttribute" parent="." instance=ExtResource("3_kqaad")]
destroy_on_death = Array[NodePath]([NodePath("..")])
spawn_on_death = ExtResource("4_y2b0x")
spawn_on_death = Array[PackedScene]([ExtResource("4_y2b0x")])
value_max = 3.0
value_start = 3.0

Expand Down
57 changes: 57 additions & 0 deletions COGITO/Enemies/body/basic_enemy_corpse.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[gd_scene load_steps=10 format=3 uid="uid://crv3r7dscbxlx"]

[ext_resource type="Script" path="res://COGITO/CogitoObjects/cogito_object.gd" id="1_gqmaj"]
[ext_resource type="PackedScene" uid="uid://cio4x05ipvslu" path="res://COGITO/Components/Interactions/CarryableComponent.tscn" id="4_dlhvl"]
[ext_resource type="AudioStream" uid="uid://cqgsihtcw0gl4" path="res://COGITO/Assets/Audio/Kenney/UiAudio/rollover1.ogg" id="5_g6e1y"]
[ext_resource type="AudioStream" uid="uid://1w0db1u6lv7t" path="res://COGITO/Assets/Audio/Kenney/UiAudio/rollover6.ogg" id="6_jxrb3"]

[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_equm6"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8jni4"]
albedo_color = Color(1, 0.12549, 0.537255, 1)

[sub_resource type="CapsuleMesh" id="CapsuleMesh_sap26"]
material = SubResource("StandardMaterial3D_8jni4")
radius = 0.4
height = 1.8

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ouco8"]
albedo_color = Color(1, 0.12549, 0.537255, 1)

[sub_resource type="BoxMesh" id="BoxMesh_35sgo"]
material = SubResource("StandardMaterial3D_ouco8")
size = Vector3(0.5, 0.32, 0.5)

[node name="corpse" type="RigidBody3D"]
transform = Transform3D(-4.37114e-08, -0.231748, -0.972776, 0, 0.972776, -0.231748, 1, -1.013e-08, -4.25214e-08, 0, 0, 0)
collision_layer = 3
mass = 65.0
continuous_cd = true
max_contacts_reported = 10
contact_monitor = true
script = ExtResource("1_gqmaj")

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.255643, 0)
shape = SubResource("CapsuleShape3D_equm6")

[node name="CarryableComponent" parent="." instance=ExtResource("4_dlhvl")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
pick_up_sound = ExtResource("5_g6e1y")
drop_sound = ExtResource("6_jxrb3")

[node name="Mesh_Body" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.245856, 0)
mesh = SubResource("CapsuleMesh_sap26")

[node name="Mesh_Face" type="MeshInstance3D" parent="Mesh_Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, -0.202423)
mesh = SubResource("BoxMesh_35sgo")

[node name="IndicatorLight" type="OmniLight3D" parent="Mesh_Body/Mesh_Face"]
transform = Transform3D(-0.707107, -0.183013, -0.683013, 0, 0.965926, -0.258819, 0.707107, -0.183013, -0.683013, 0.0609554, -0.00331843, -0.478758)
light_color = Color(1, 0, 0, 1)
light_energy = 0.1

[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
5 changes: 3 additions & 2 deletions COGITO/Enemies/cogito_basic_enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=25 format=3 uid="uid://dn4e1k7u3suoo"]
[gd_scene load_steps=26 format=3 uid="uid://dn4e1k7u3suoo"]

[ext_resource type="Script" path="res://COGITO/Enemies/cogito_basic_enemy.gd" id="1_0lcvu"]
[ext_resource type="Script" path="res://COGITO/CogitoObjects/cogito_security_camera.gd" id="2_6jysp"]
Expand All @@ -7,6 +7,7 @@
[ext_resource type="PackedScene" uid="uid://cqgg1nng0vvbh" path="res://COGITO/Components/Attributes/HealthAttribute.tscn" id="4_y8n8v"]
[ext_resource type="PackedScene" uid="uid://bc2hryr610vgo" path="res://COGITO/PackedScenes/simple_particle_puff.tscn" id="5_ni6ul"]
[ext_resource type="Script" path="res://COGITO/Components/HitboxComponent.gd" id="5_qh1ls"]
[ext_resource type="PackedScene" uid="uid://crv3r7dscbxlx" path="res://COGITO/Enemies/body/basic_enemy_corpse.tscn" id="7_8vdb4"]
[ext_resource type="PackedScene" uid="uid://cj0yaeh3yg7tu" path="res://COGITO/Components/Properties/CogitoProperties.tscn" id="7_15n6t"]
[ext_resource type="AudioStream" uid="uid://up2hfhgq1qx6" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep00.ogg" id="8_vyi83"]
[ext_resource type="AudioStream" uid="uid://crj07wq4oocwi" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep01.ogg" id="9_5fsuu"]
Expand Down Expand Up @@ -111,7 +112,7 @@ bus = &"SFX"

[node name="HealthAttribute" parent="." instance=ExtResource("4_y8n8v")]
destroy_on_death = Array[NodePath]([NodePath("..")])
spawn_on_death = ExtResource("5_ni6ul")
spawn_on_death = Array[PackedScene]([ExtResource("5_ni6ul"), ExtResource("7_8vdb4")])
value_max = 5.0
value_start = 5.0

Expand Down