Add logic to convert item to other

This commit is contained in:
JonShard
2026-07-14 15:38:01 +02:00
parent 6dbade14a2
commit 32f4b92983
8 changed files with 206 additions and 24 deletions
+48
View File
@@ -0,0 +1,48 @@
[gd_scene format=3 uid="uid://cucc3gaqu2nab"]
[ext_resource type="PackedScene" uid="uid://c8l60rnugru40" path="res://addons/godot-xr-tools/objects/pickable.tscn" id="1_r73y2"]
[ext_resource type="PackedScene" uid="uid://c25yxb0vt53vc" path="res://addons/godot-xr-tools/objects/grab_points/grab_point_hand_left.tscn" id="2_nfmuy"]
[ext_resource type="Animation" uid="uid://db62hs5s4n2b3" path="res://addons/godot-xr-tools/hands/animations/left/Grip 4.res" id="3_bsb6f"]
[ext_resource type="Script" uid="uid://dvobm6vcfnqe8" path="res://addons/godot-xr-tools/hands/poses/hand_pose_settings.gd" id="4_mgacb"]
[ext_resource type="PackedScene" uid="uid://ctw7nbntd5pcj" path="res://addons/godot-xr-tools/objects/grab_points/grab_point_hand_right.tscn" id="5_vw7i6"]
[ext_resource type="Animation" uid="uid://d1xnpyc08njjx" path="res://addons/godot-xr-tools/hands/animations/right/Grip 4.res" id="6_cp3eg"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_gkni8"]
custom_solver_bias = 0.1
height = 0.1
radius = 0.1
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_e28iu"]
albedo_color = Color(0.06879827, 0.06879828, 0.06879828, 1)
[sub_resource type="CylinderMesh" id="CylinderMesh_vebgy"]
material = SubResource("StandardMaterial3D_e28iu")
top_radius = 0.1
bottom_radius = 0.1
height = 0.1
[sub_resource type="Resource" id="Resource_lc22d"]
script = ExtResource("4_mgacb")
closed_pose = ExtResource("3_bsb6f")
metadata/_custom_type_script = "uid://dvobm6vcfnqe8"
[sub_resource type="Resource" id="Resource_qyiot"]
script = ExtResource("4_mgacb")
closed_pose = ExtResource("6_cp3eg")
metadata/_custom_type_script = "uid://dvobm6vcfnqe8"
[node name="PickableObject" unique_id=1675596942 instance=ExtResource("1_r73y2")]
[node name="CollisionShape3D" parent="." index="0"]
shape = SubResource("CylinderShape3D_gkni8")
[node name="MeshInstance3D" type="MeshInstance3D" parent="." index="1" unique_id=1223689787]
mesh = SubResource("CylinderMesh_vebgy")
[node name="GrabPointHandLeft" parent="." index="2" unique_id=1571481674 instance=ExtResource("2_nfmuy")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.067650706, 0.04601878, -0.08606844)
hand_pose = SubResource("Resource_lc22d")
[node name="GrabPointHandRight" parent="." index="3" unique_id=514404634 instance=ExtResource("5_vw7i6")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06531982, 0.042291984, -0.08604182)
hand_pose = SubResource("Resource_qyiot")
+7 -2
View File
@@ -6,6 +6,8 @@
[ext_resource type="Script" uid="uid://dvobm6vcfnqe8" path="res://addons/godot-xr-tools/hands/poses/hand_pose_settings.gd" id="4_hc3f7"]
[ext_resource type="PackedScene" uid="uid://ctw7nbntd5pcj" path="res://addons/godot-xr-tools/objects/grab_points/grab_point_hand_right.tscn" id="5_a0a5b"]
[ext_resource type="Animation" uid="uid://d1xnpyc08njjx" path="res://addons/godot-xr-tools/hands/animations/right/Grip 4.res" id="6_bdp75"]
[ext_resource type="Script" uid="uid://bs7cxydoxk1cx" path="res://cookable_item.gd" id="7_hc3f7"]
[ext_resource type="PackedScene" uid="uid://cucc3gaqu2nab" path="res://Charcoal.tscn" id="8_a0a5b"]
[sub_resource type="BoxShape3D" id="BoxShape3D_m1xbq"]
size = Vector3(0.1, 0.1, 0.1)
@@ -37,10 +39,13 @@ mesh = SubResource("BoxMesh_vlqg6")
[node name="GrabPointHandLeft" parent="." index="2" unique_id=1571481674 instance=ExtResource("2_pxnkq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.067650706, 0.04601878, -0.08606844)
visible = true
hand_pose = SubResource("Resource_lc22d")
[node name="GrabPointHandRight" parent="." index="3" unique_id=514404634 instance=ExtResource("5_a0a5b")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06531982, 0.042291984, -0.08604182)
visible = true
hand_pose = SubResource("Resource_qyiot")
[node name="CookableItem" type="Node" parent="." index="4" unique_id=1139889801]
script = ExtResource("7_hc3f7")
cooking_time = 2.0
turns_into = ExtResource("8_a0a5b")
+9
View File
@@ -0,0 +1,9 @@
class_name CookableItem
extends Node
@export_range(0.0, 30.0, 0.5, "or_greater", "suffix:s") var cooking_time: float = 4.0
@export var turns_into: PackedScene
func _ready() -> void:
if not turns_into:
push_error("Cooking Error: 'turns_into' PackedScene is missing on ", name, ". Please assign a scene in the Inspector.")
+1
View File
@@ -0,0 +1 @@
uid://bs7cxydoxk1cx
+61
View File
@@ -0,0 +1,61 @@
extends StaticBody3D
@export var cook_speed = 1
@onready var snap_zone: XRToolsSnapZone = $XRToolsSnapZone
var item = null
var progress = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if snap_zone.initial_object:
item = snap_zone.initial_object
print("Hob has item: ", item)
else:
print("Hob is empty")
func convert_item(cookable: CookableItem) -> void:
print("Converting ", cookable)
var old_pickable = snap_zone.picked_up_object
if not old_pickable:
push_warning("Hob finished cooking item, but snap zone is missing its reference")
return
print("picked_up_object ", snap_zone.picked_up_object)
var original_transform = old_pickable.global_transform
var new_scene_instance = cookable.turns_into.instantiate()
# Add the new item to the hob's parent (so it lives in the main world space)
get_parent().add_child(new_scene_instance)
new_scene_instance.global_transform = original_transform
snap_zone.drop_object()
print("old_pickable ", old_pickable)
old_pickable.queue_free()
snap_zone.pick_up_object(new_scene_instance)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
print("Picked obj:", snap_zone.picked_up_object)
# Find the CookableItem in held object
var cookable = null
if snap_zone.picked_up_object:
var matches = snap_zone.picked_up_object.get_children().filter(func(c): return c is CookableItem)
if matches.size() > 0:
cookable = matches[0]
# Cook it if exists, then convert item after cooking
if cookable:
progress += cook_speed * delta
print("Cooking ", progress)
if progress >= cookable.cooking_time:
progress = 0
convert_item(cookable)
else:
progress = 0
+1
View File
@@ -0,0 +1 @@
uid://bsn8vhv5adxdo
+64 -22
View File
@@ -2,11 +2,9 @@
[ext_resource type="Script" uid="uid://b4ldkd3ngs0vp" path="res://main.gd" id="1_0xm2m"]
[ext_resource type="PackedScene" uid="uid://j5s5wus7tuhb" path="res://XROrigin.tscn" id="2_h2yge"]
[ext_resource type="Script" uid="uid://cquqe4f1m1sw6" path="res://addons/godot-xr-tools/objects/snap_zone.gd" id="3_1bvp3"]
[ext_resource type="PackedScene" uid="uid://e4i6o5oriecx" path="res://PickupCube.tscn" id="3_h2yge"]
[sub_resource type="BoxShape3D" id="BoxShape3D_24d3s"]
[sub_resource type="BoxMesh" id="BoxMesh_i5j2u"]
[ext_resource type="Script" uid="uid://bsn8vhv5adxdo" path="res://hob.gd" id="3_lquwl"]
[sub_resource type="BoxShape3D" id="BoxShape3D_vlqg6"]
size = Vector3(5, 0.1, 5)
@@ -14,21 +12,20 @@ size = Vector3(5, 0.1, 5)
[sub_resource type="BoxMesh" id="BoxMesh_24d3s"]
size = Vector3(5, 0.1, 5)
[sub_resource type="BoxShape3D" id="BoxShape3D_24d3s"]
[sub_resource type="BoxMesh" id="BoxMesh_i5j2u"]
[sub_resource type="SphereShape3D" id="SphereShape3D_vlqg6"]
[node name="Main" type="Node3D" unique_id=1312265607]
script = ExtResource("1_0xm2m")
[node name="XROrigin3D" parent="." unique_id=2055526621 instance=ExtResource("2_h2yge")]
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="." unique_id=1376644384]
transform = Transform3D(-0.8660254, -0.43301278, 0.24999999, 0.3022632, -0.05510214, 0.9516306, -0.39829266, 0.8997021, 0.17860365, 0, 0, 0)
[node name="Box" type="StaticBody3D" parent="." unique_id=799977363]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, -1.484)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Box" unique_id=709939046]
shape = SubResource("BoxShape3D_24d3s")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Box/CollisionShape3D" unique_id=764879781]
mesh = SubResource("BoxMesh_i5j2u")
[node name="Floor" type="StaticBody3D" parent="." unique_id=122279514]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.05, 0)
@@ -38,16 +35,61 @@ shape = SubResource("BoxShape3D_vlqg6")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Floor/CollisionShape3D" unique_id=1939997056]
mesh = SubResource("BoxMesh_24d3s")
[node name="XROrigin3D" parent="." unique_id=2055526621 instance=ExtResource("2_h2yge")]
[node name="Hob" type="StaticBody3D" parent="." unique_id=799977363]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.29336345, 0.5, -1.484)
script = ExtResource("3_lquwl")
[node name="PickableObject" parent="." unique_id=1675596942 instance=ExtResource("3_h2yge")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0957007, -1.1400242)
[node name="Box2" type="StaticBody3D" parent="." unique_id=191478406]
transform = Transform3D(1, 0, 0, 0, 5, 0, 0, 0, 1, 0, 0.5, 1.9750495)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Box2" unique_id=1818266327]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Hob" unique_id=709939046]
shape = SubResource("BoxShape3D_24d3s")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Box2/CollisionShape3D" unique_id=1977518613]
[node name="MeshInstance3D" type="MeshInstance3D" parent="Hob/CollisionShape3D" unique_id=764879781]
mesh = SubResource("BoxMesh_i5j2u")
[node name="Label3D" type="Label3D" parent="Hob/CollisionShape3D" unique_id=1357581958]
transform = Transform3D(0.9999992, 0, 0, 0, 0.99999946, 0, 0, 0, 0.9999992, 0.002797456, 0.6309581, -0.2812457)
text = "Hob"
[node name="XRToolsSnapZone" type="Area3D" parent="Hob" unique_id=282181673]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5270121, 0)
collision_layer = 65536
collision_mask = 65536
script = ExtResource("3_1bvp3")
snap_mode = 1
initial_object = NodePath("../../PickableObject2")
metadata/_custom_type_script = "uid://cquqe4f1m1sw6"
[node name="CollisionShape3D2" type="CollisionShape3D" parent="Hob/XRToolsSnapZone" unique_id=808936665]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, -0.000975132, 0)
shape = SubResource("SphereShape3D_vlqg6")
[node name="Counter" type="StaticBody3D" parent="." unique_id=1606773951]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.7321187, 0.5, -1.484)
[node name="CollisionShape3D" type="CollisionShape3D" parent="Counter" unique_id=1488758675]
shape = SubResource("BoxShape3D_24d3s")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Counter/CollisionShape3D" unique_id=1356208894]
mesh = SubResource("BoxMesh_i5j2u")
[node name="Label3D" type="Label3D" parent="Counter/CollisionShape3D" unique_id=1406314269]
transform = Transform3D(0.9999992, 0, 0, 0, 0.99999946, 0, 0, 0, 0.9999992, 0.002797456, 0.6309581, -0.2812457)
text = "Counter"
[node name="XRToolsSnapZone" type="Area3D" parent="Counter" unique_id=1197324324]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5270121, 0)
collision_layer = 0
collision_mask = 65537
script = ExtResource("3_1bvp3")
snap_mode = 1
initial_object = NodePath("../../PickableObject")
metadata/_custom_type_script = "uid://cquqe4f1m1sw6"
[node name="CollisionShape3D2" type="CollisionShape3D" parent="Counter/XRToolsSnapZone" unique_id=1304830059]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, -0.000975132, 0)
shape = SubResource("SphereShape3D_vlqg6")
[node name="PickableObject" parent="." unique_id=1675596942 instance=ExtResource("3_h2yge")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, -0.70505303, 1.1780516, -1.4470987)
[node name="PickableObject2" parent="." unique_id=713087634 instance=ExtResource("3_h2yge")]
transform = Transform3D(1, 0, -2.2351742e-08, -2.9802322e-08, 1.0000001, 0, -2.6077032e-08, 1.4901161e-08, 1, 0.28315204, 1.1626935, -1.4811357)
+15
View File
@@ -29,6 +29,21 @@ window/stretch/aspect="expand"
enabled=PackedStringArray("res://addons/godot-xr-tools/plugin.cfg")
[layer_names]
3d_physics/layer_1="Static World"
3d_physics/layer_2="Dynamic World"
3d_physics/layer_3="Pickable Objects"
3d_physics/layer_4="Wall Walking"
3d_physics/layer_5="Grappling Target"
3d_physics/layer_17="Held Objects"
3d_physics/layer_18="Player Hands"
3d_physics/layer_19="Grab Handles"
3d_physics/layer_20="Player Body"
3d_physics/layer_21="Pointable Objects"
3d_physics/layer_22="Hand Pose Areas"
3d_physics/layer_23="UI Objects"
[physics]
3d/physics_engine="Jolt Physics"