Преглед изворни кода

Make chocolate collectable

DricomDragon пре 3 месеци
родитељ
комит
1f4427cbd9

+ 12 - 0
godot/component/entity/collectibles/chocolate/chocolate.gd

@@ -0,0 +1,12 @@
+class_name Chocolate
+extends Area3D
+
+
+func _on_body_entered(body: Node3D) -> void:
+	print("Body entered in chocolate : ", body)
+	if body is Walker:
+		_give_chocolate_to(body)
+
+func _give_chocolate_to(walker: Walker) -> void:
+	walker.give_chocolate()
+	queue_free()

+ 8 - 1
godot/component/entity/collectibles/chocolate/chocolate.tscn

@@ -1,4 +1,6 @@
-[gd_scene load_steps=6 format=3 uid="uid://ba3gf7iy3mxbq"]
+[gd_scene load_steps=7 format=3 uid="uid://ba3gf7iy3mxbq"]
+
+[ext_resource type="Script" path="res://component/entity/collectibles/chocolate/chocolate.gd" id="1_wk24q"]
 
 [sub_resource type="BoxShape3D" id="BoxShape3D_cro6x"]
 size = Vector3(1, 1, 0.325)
@@ -20,6 +22,9 @@ material = SubResource("StandardMaterial3D_ds5yo")
 size = Vector3(0.85, 0.8, 0.25)
 
 [node name="ChocolateTablet" type="Area3D"]
+collision_layer = 32
+collision_mask = 10
+script = ExtResource("1_wk24q")
 
 [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
 shape = SubResource("BoxShape3D_cro6x")
@@ -30,3 +35,5 @@ mesh = SubResource("BoxMesh_c10ab")
 [node name="PaperMesh" type="MeshInstance3D" parent="."]
 transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.119209, 0)
 mesh = SubResource("BoxMesh_ialpe")
+
+[connection signal="body_entered" from="." to="." method="_on_body_entered"]

+ 5 - 0
godot/component/entity/walker/walker.gd

@@ -54,6 +54,11 @@ func can_get_in_vehicle() -> bool:
 	return !is_onboard() and _get_closest_vehicle() != null
 
 
+## Give this walker a chocolate bar
+func give_chocolate():
+	print("Yum, chocolate !")
+
+
 func _physics_process(delta: float) -> void:
 	if is_onboard():
 		_get_on_driver_seat()

+ 1 - 0
godot/project.godot

@@ -123,6 +123,7 @@ locale/locale_filter_mode=1
 3d_physics/layer_3="danger"
 3d_physics/layer_4="vehicle"
 3d_physics/layer_5="props"
+3d_physics/layer_6="collectibles"
 
 [rendering]