feat: enemy death and damage effects

This commit is contained in:
Sara 2025-07-23 00:24:52 +02:00
parent 2134fcae92
commit 1a8c64806d
13 changed files with 96 additions and 7 deletions

View file

@ -2,7 +2,9 @@
#include "macros.h" #include "macros.h"
#include "npc_unit.h" #include "npc_unit.h"
void EnemyBody::_bind_methods() {} void EnemyBody::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_movement_direction", "direction"), &self_type::set_movement_direction);
}
void EnemyBody::ready() { void EnemyBody::ready() {
this->fsm = cast_to<StateMachine>(get_node(NodePath("%StateMachine"))); this->fsm = cast_to<StateMachine>(get_node(NodePath("%StateMachine")));

View file

@ -5,6 +5,7 @@
void Hitbox::_bind_methods() { void Hitbox::_bind_methods() {
BIND_HPROPERTY(Variant::OBJECT, health, PROPERTY_HINT_NODE_TYPE, "HealthStatus"); BIND_HPROPERTY(Variant::OBJECT, health, PROPERTY_HINT_NODE_TYPE, "HealthStatus");
BIND_PROPERTY(Variant::FLOAT, damage_modifier); BIND_PROPERTY(Variant::FLOAT, damage_modifier);
BIND_HPROPERTY(Variant::OBJECT, impact_effect, PROPERTY_HINT_RESOURCE_TYPE, "PackedScene");
} }
void Hitbox::set_health(HealthStatus *value) { void Hitbox::set_health(HealthStatus *value) {
@ -22,3 +23,11 @@ void Hitbox::set_damage_modifier(float value) {
float Hitbox::get_damage_modifier() const { float Hitbox::get_damage_modifier() const {
return this->damage_modifier; return this->damage_modifier;
} }
void Hitbox::set_impact_effect(Ref<PackedScene> effect) {
this->impact_effect = effect;
}
Ref<PackedScene> Hitbox::get_impact_effect() const {
return this->impact_effect;
}

View file

@ -2,6 +2,7 @@
#define HITBOX_H #define HITBOX_H
#include "scene/3d/physics/area_3d.h" #include "scene/3d/physics/area_3d.h"
#include "scene/resources/packed_scene.h"
class HealthStatus; class HealthStatus;
class Hitbox : public Area3D { class Hitbox : public Area3D {
@ -14,9 +15,13 @@ public:
void set_damage_modifier(float value); void set_damage_modifier(float value);
float get_damage_modifier() const; float get_damage_modifier() const;
void set_impact_effect(Ref<PackedScene> scene);
Ref<PackedScene> get_impact_effect() const;
private: private:
HealthStatus *health{ nullptr }; HealthStatus *health{ nullptr };
float damage_modifier{ 1.f }; float damage_modifier{ 1.f };
Ref<PackedScene> impact_effect{};
}; };
#endif // !HITBOX_H #endif // !HITBOX_H

View file

@ -14,9 +14,13 @@ void HitscanMuzzle::instantiate_impact_effect() {
if (get_collider() == nullptr) { if (get_collider() == nullptr) {
return; return;
} }
Node *effect_as_node{ this->impact_effect->instantiate() }; Ref<PackedScene> effect_scene{ get_collider()->call("get_impact_effect") };
if (!effect_scene.is_valid()) {
effect_scene = this->impact_effect;
}
Node *effect_as_node{ effect_scene->instantiate() };
if (Node3D * effect{ cast_to<Node3D>(effect_as_node) }) { if (Node3D * effect{ cast_to<Node3D>(effect_as_node) }) {
get_tree()->get_current_scene()->add_child(effect); cast_to<Node>(get_collider())->add_child(effect);
Vector3 const point{ get_collision_point() }; Vector3 const point{ get_collision_point() };
Vector3 const normal{ get_collision_normal() }; Vector3 const normal{ get_collision_normal() };
Vector3 const position{ get_global_position() }; Vector3 const position{ get_global_position() };

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=6 format=3 uid="uid://crtgy2rph5to2"] [gd_scene load_steps=7 format=3 uid="uid://crtgy2rph5to2"]
[ext_resource type="PackedScene" uid="uid://ho7wwawj6s65" path="res://assets/models/enemies/wretched.blend" id="1_w0sx6"] [ext_resource type="PackedScene" uid="uid://ho7wwawj6s65" path="res://assets/models/enemies/wretched.blend" id="1_w0sx6"]
[ext_resource type="PackedScene" uid="uid://clbq43giddldc" path="res://objects/effects/blood_effect.tscn" id="2_a12c4"]
[sub_resource type="BoxShape3D" id="BoxShape3D_w0sx6"] [sub_resource type="BoxShape3D" id="BoxShape3D_w0sx6"]
size = Vector3(0.35351563, 0.8721161, 0.29003906) size = Vector3(0.35351563, 0.8721161, 0.29003906)
@ -21,6 +22,7 @@ transform = Transform3D(1, 2.1910389e-16, -2.2202524e-16, -2.2202514e-16, 0.9999
collision_layer = 6 collision_layer = 6
collision_mask = 0 collision_mask = 0
monitoring = false monitoring = false
impact_effect = ExtResource("2_a12c4")
[node name="CollisionShape3D2" type="CollisionShape3D" parent="Character/Skeleton3D/Hitbox" index="0"] [node name="CollisionShape3D2" type="CollisionShape3D" parent="Character/Skeleton3D/Hitbox" index="0"]
transform = Transform3D(1, 5.875464e-21, 0, 6.2038546e-25, 1.0000037, 0, 0, 0, 1.0000037, -2.2362435e-16, 0.35283393, -0.013339132) transform = Transform3D(1, 5.875464e-21, 0, 6.2038546e-25, 1.0000037, 0, 0, 0, 1.0000037, -2.2362435e-16, 0.35283393, -0.013339132)
@ -36,6 +38,7 @@ transform = Transform3D(1, 2.1910389e-16, -2.2202524e-16, -2.2202514e-16, 0.9999
collision_layer = 4 collision_layer = 4
collision_mask = 0 collision_mask = 0
monitoring = false monitoring = false
impact_effect = ExtResource("2_a12c4")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Character/Skeleton3D/SpineAttach/Hitbox" index="0"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Character/Skeleton3D/SpineAttach/Hitbox" index="0"]
transform = Transform3D(1, -2.2202515e-16, 2.1910396e-16, 2.1910385e-16, 0.9999122, 0.0132439565, -2.2202522e-16, -0.013243958, 0.99991226, 0.0023498535, 1.1967317, -0.0032694251) transform = Transform3D(1, -2.2202515e-16, 2.1910396e-16, 2.1910385e-16, 0.9999122, 0.0132439565, -2.2202522e-16, -0.013243958, 0.99991226, 0.0023498535, 1.1967317, -0.0032694251)
@ -52,6 +55,7 @@ collision_layer = 4
collision_mask = 0 collision_mask = 0
monitoring = false monitoring = false
damage_modifier = 2.0 damage_modifier = 2.0
impact_effect = ExtResource("2_a12c4")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Character/Skeleton3D/HeadAttach/Hitbox" index="0"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Character/Skeleton3D/HeadAttach/Hitbox" index="0"]
transform = Transform3D(1, -2.2202515e-16, 2.1910393e-16, 2.1910723e-16, 0.9999161, 0.013243863, -2.2202641e-16, -0.013243858, 0.9999161, -7.644832e-17, 1.3035276, -0.01432839) transform = Transform3D(1, -2.2202515e-16, 2.1910393e-16, 2.1910723e-16, 0.9999161, 0.013243863, -2.2202641e-16, -0.013243858, 0.9999161, -7.644832e-17, 1.3035276, -0.01432839)

View file

@ -0,0 +1,56 @@
[gd_scene load_steps=7 format=3 uid="uid://clbq43giddldc"]
[sub_resource type="GDScript" id="GDScript_abt0s"]
script/source = "extends Node3D
func _init():
set_disable_scale(true)
func _ready():
$GPUParticles3D.emitting = true
"
[sub_resource type="Curve" id="Curve_abt0s"]
_data = [Vector2(0.55064934, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), -3.5361242, 0.0, 0, 0]
point_count = 2
[sub_resource type="CurveTexture" id="CurveTexture_rtbd5"]
curve = SubResource("Curve_abt0s")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_abt0s"]
direction = Vector3(0, 0, -1)
spread = 5.0
initial_velocity_min = 1.0
initial_velocity_max = 3.0
scale_curve = SubResource("CurveTexture_rtbd5")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_rtbd5"]
shading_mode = 2
diffuse_mode = 1
specular_mode = 2
albedo_color = Color(0.7921569, 0.09803922, 0.09019608, 1)
[sub_resource type="QuadMesh" id="QuadMesh_qrff5"]
material = SubResource("StandardMaterial3D_rtbd5")
size = Vector2(0.3, 0.3)
[node name="BloodEffect" type="Node3D"]
script = SubResource("GDScript_abt0s")
[node name="Timer" type="Timer" parent="."]
wait_time = 0.2
one_shot = true
autostart = true
[node name="GPUParticles3D" type="GPUParticles3D" parent="."]
emitting = false
amount = 10
lifetime = 0.2
one_shot = true
explosiveness = 0.6
fixed_fps = 10
transform_align = 3
process_material = SubResource("ParticleProcessMaterial_abt0s")
draw_pass_1 = SubResource("QuadMesh_qrff5")
[connection signal="timeout" from="Timer" to="." method="queue_free"]

View file

@ -6,7 +6,10 @@
script/source = "extends EnemyWretched script/source = "extends EnemyWretched
func _on_health_status_death() -> void: func _on_health_status_death() -> void:
queue_free(); %StateMachine.set_process(false)
$wretched/AnimationPlayer.play(\"death\")
$CollisionShape3D.disabled = true
set_movement_direction(Vector2())
" "
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_ng1ul"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_ng1ul"]
@ -20,9 +23,15 @@ script = SubResource("GDScript_qot2n")
[node name="Hitbox" parent="wretched/Character/Skeleton3D" index="2" node_paths=PackedStringArray("health")] [node name="Hitbox" parent="wretched/Character/Skeleton3D" index="2" node_paths=PackedStringArray("health")]
health = NodePath("../../../../HealthStatus") health = NodePath("../../../../HealthStatus")
[node name="SpineAttach" parent="wretched/Character/Skeleton3D" index="3"]
transform = Transform3D(1, -2.2202518e-16, 2.1910394e-16, 2.1910388e-16, 0.9999122, 0.013243958, -2.220252e-16, -0.01324396, 0.99991226, -4.1256417e-17, 1.1546816, -0.0027124756)
[node name="Hitbox" parent="wretched/Character/Skeleton3D/SpineAttach" index="0" node_paths=PackedStringArray("health")] [node name="Hitbox" parent="wretched/Character/Skeleton3D/SpineAttach" index="0" node_paths=PackedStringArray("health")]
health = NodePath("../../../../../HealthStatus") health = NodePath("../../../../../HealthStatus")
[node name="HeadAttach" parent="wretched/Character/Skeleton3D" index="4"]
transform = Transform3D(0.9999988, -0.0007823897, 0.0013344375, 0.0007271601, 0.99916273, 0.04089782, -0.0013653187, -0.040896803, 0.9991622, -1.3069549e-16, 1.5574794, -0.004068734)
[node name="Hitbox" parent="wretched/Character/Skeleton3D/HeadAttach" index="0" node_paths=PackedStringArray("health")] [node name="Hitbox" parent="wretched/Character/Skeleton3D/HeadAttach" index="0" node_paths=PackedStringArray("health")]
health = NodePath("../../../../../HealthStatus") health = NodePath("../../../../../HealthStatus")

View file

@ -8,10 +8,10 @@
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, -1.1853347, 0.023195954, -0.8597343) transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, -1.1853347, 0.023195954, -0.8597343)
[node name="EnemyWretched5" parent="." instance=ExtResource("1_l77gx")] [node name="EnemyWretched5" parent="." instance=ExtResource("1_l77gx")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0.3304333, 0.023195954, 1.0620495) transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0.30714047, 0.023195954, 0.58812845)
[node name="EnemyWretched6" parent="." instance=ExtResource("1_l77gx")] [node name="EnemyWretched6" parent="." instance=ExtResource("1_l77gx")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0.026455224, 0.023195954, -1.7789332) transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0.05460906, 0.023195954, -1.4555124)
[node name="EnemyWretched7" parent="." instance=ExtResource("1_l77gx")] [node name="EnemyWretched7" parent="." instance=ExtResource("1_l77gx")]
transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0.054681122, 0.023195954, -0.4100113) transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0.054681122, 0.023195954, -0.4100113)