Browse Source

Add fade out animation when chocolate is collected

DricomDragon 1 week ago
parent
commit
07bbafa438

+ 16 - 3
godot/component/entity/collectibles/chocolate/chocolate.gd

@@ -1,11 +1,24 @@
 class_name Chocolate
-extends Area3D
+extends Node3D
 
 
-func _on_body_entered(body: Node3D) -> void:
+const COLLECT_ANIM := "collection"
+
+@onready var chocolateAnimation: AnimationPlayer = $ChocolateAnimation
+
+
+func _on_chocolate_tablet_body_entered(body: Node3D) -> void:
 	if body is Walker:
 		_give_chocolate_to(body)
 
+
 func _give_chocolate_to(walker: Walker) -> void:
 	walker.give_chocolate()
-	queue_free()
+	chocolateAnimation.play(COLLECT_ANIM)
+	chocolateAnimation.animation_finished.connect(_finish)
+
+
+func _finish(animation_name: String) -> void:
+	if COLLECT_ANIM == animation_name:
+		# Collection is finished
+		queue_free()

+ 23 - 3
godot/component/entity/collectibles/chocolate/chocolate.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=10 format=3 uid="uid://ba3gf7iy3mxbq"]
+[gd_scene load_steps=11 format=3 uid="uid://ba3gf7iy3mxbq"]
 
 [ext_resource type="Script" path="res://component/entity/collectibles/chocolate/chocolate.gd" id="1_wk24q"]
 
@@ -32,9 +32,29 @@ tracks/0/interp = 1
 tracks/0/loop_wrap = true
 tracks/0/keys = PackedFloat32Array(0, 1, 0, 0, 0, 1)
 
+[sub_resource type="Animation" id="Animation_d6qxv"]
+resource_name = "collection"
+length = 2.0
+step = 0.25
+tracks/0/type = "rotation_3d"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath(".")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/keys = PackedFloat32Array(0, 1, 0, 0, 0, 1, 0.5, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, -1, 1.5, 1, 0, -1, 0, 0, 2, 1, 0, 0, 0, 1)
+tracks/1/type = "scale_3d"
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/path = NodePath(".")
+tracks/1/interp = 2
+tracks/1/loop_wrap = true
+tracks/1/keys = PackedFloat32Array(1, 1, 1, 1, 1, 2, 1, 0, 0, 0)
+
 [sub_resource type="AnimationLibrary" id="AnimationLibrary_djjxd"]
 _data = {
 "RESET": SubResource("Animation_cfly2"),
+"collection": SubResource("Animation_d6qxv"),
 "idle": SubResource("Animation_0f754")
 }
 
@@ -58,6 +78,7 @@ material = SubResource("StandardMaterial3D_ds5yo")
 size = Vector3(0.85, 0.8, 0.25)
 
 [node name="Chocolate" type="Node3D"]
+script = ExtResource("1_wk24q")
 
 [node name="ChocolateAnimation" type="AnimationPlayer" parent="."]
 root_node = NodePath("../ChocolateTablet")
@@ -69,7 +90,6 @@ autoplay = "idle"
 [node name="ChocolateTablet" type="Area3D" parent="."]
 collision_layer = 32
 collision_mask = 10
-script = ExtResource("1_wk24q")
 
 [node name="ChocolateCollisionShape3D" type="CollisionShape3D" parent="ChocolateTablet"]
 transform = Transform3D(1, 0, 1.74846e-07, 0, 1, 0, -1.74846e-07, 0, 1, 0, 0, 0)
@@ -82,4 +102,4 @@ mesh = SubResource("BoxMesh_c10ab")
 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.119209, 0)
 mesh = SubResource("BoxMesh_ialpe")
 
-[connection signal="body_entered" from="ChocolateTablet" to="ChocolateTablet" method="_on_body_entered"]
+[connection signal="body_entered" from="ChocolateTablet" to="." method="_on_chocolate_tablet_body_entered"]