Improved socket script and added hologram logic to show preview of where the pickupable will attach. Also added lock and key meshes.
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
[gd_resource type="StandardMaterial3D" format=3 uid="uid://cgv3rv0ll5vul"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
transparency = 1
|
||||||
|
albedo_color = Color(4.428029e-06, 0.8795453, 0.8031044, 0.38039216)
|
||||||
|
emission_enabled = true
|
||||||
|
emission = Color(0.2620934, 0.84187055, 0.94188195, 1)
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+62
-12
@@ -1,32 +1,82 @@
|
|||||||
[gd_scene format=3 uid="uid://dknge5384ijcx"]
|
[gd_scene format=3 uid="uid://dknge5384ijcx"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://b143brnl7gf4f" path="res://Scripts/Pickupable.gd" id="1_rsor3"]
|
[ext_resource type="Script" uid="uid://b143brnl7gf4f" path="res://Scripts/Pickupable.gd" id="1_rsor3"]
|
||||||
|
[ext_resource type="ArrayMesh" uid="uid://d12dor1swnt0b" path="res://Meshes/KeyMesh.tres" id="2_w4i4f"]
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1blfk"]
|
|
||||||
size = Vector3(0.1, 0.1, 0.2)
|
|
||||||
|
|
||||||
[sub_resource type="BoxMesh" id="BoxMesh_va8t4"]
|
|
||||||
size = Vector3(0.1, 0.1, 0.3)
|
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_w4i4f"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_w4i4f"]
|
||||||
albedo_color = Color(1, 1, 0, 1)
|
albedo_color = Color(1, 1, 0, 1)
|
||||||
|
|
||||||
[node name="SimpleKey" type="Node3D" unique_id=650555678 node_paths=PackedStringArray("body", "snapAnchor")]
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_w4i4f"]
|
||||||
|
points = PackedVector3Array(0.2587716, -0.12591924, -0.03817381, 0.24755853, 0.15451507, 0.02913095, 0.23633888, 0.15451507, 0.02913095, 0.23633888, -0.13713889, 0.02913095, 0.23633888, 0.15451507, -0.03817381, 0.26999125, 0.12085611, 0.02913095, 0.26999125, 0.12085611, -0.03817381, 0.26999125, -0.10347992, 0.02913095, 0.23633888, -0.13713889, -0.03817381, 0.26999125, -0.10347992, -0.03817381, 0.24755853, -0.13713889, 0.02913095, 0.2587716, 0.14329542, -0.03817381, 0.24755853, -0.13713889, -0.03817381, 0.24755853, 0.15451507, -0.03817381, 0.2587716, -0.12591924, 0.02913095, 0.2587716, 0.14329542, 0.02913095)
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_ycjx8"]
|
||||||
|
points = PackedVector3Array(0.23633888, 0.17694777, 0.02913095, 0.10172936, -0.14829704, -0.03817381, 0.11295561, -0.15957159, -0.03817381, 0.10172936, -0.14829704, 0.02913095, 0.10172936, 0.16571055, -0.03817381, 0.23633888, -0.15957159, -0.03817381, 0.23633888, -0.15957159, 0.02913095, 0.23633888, 0.17694777, -0.03817381, 0.10172936, 0.16571055, 0.02913095, 0.14662117, 0.1993849, -0.03817381, 0.14662117, -0.18200871, 0.02913095, 0.2026865, 0.1993849, 0.02913095, 0.2026865, -0.18200871, -0.03817381, 0.14662117, 0.1993849, 0.02913095, 0.2026865, -0.18200871, 0.02913095, 0.14662117, -0.18200871, -0.03817381, 0.2026865, 0.1993849, -0.03817381, 0.12418185, 0.18814766, -0.03817381, 0.12418185, -0.17077148, 0.02913095, 0.12418185, 0.18814766, 0.02913095, 0.22511265, -0.17077148, 0.02913095, 0.22511265, 0.18814766, -0.03817381, 0.12418185, -0.17077148, -0.03817381, 0.22511265, -0.17077148, -0.03817381, 0.22511265, 0.18814766, 0.02913095)
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_qtgaf"]
|
||||||
|
points = PackedVector3Array(0.07929663, -0.10346894, -0.03817381, 0.10172716, 0.14329761, 0.02913095, 0.10172716, 0.14329761, -0.03817381, 0.10172716, -0.12592143, 0.02913095, 0.07929663, 0.120845124, 0.02913095, 0.10172716, -0.12592143, -0.03817381, 0.07929663, 0.120845124, -0.03817381, 0.07929663, -0.10346894, 0.02913095, 0.0905108, -0.12592143, 0.02913095, 0.0905108, 0.14329761, -0.03817381, 0.0905108, -0.12592143, -0.03817381, 0.0905108, 0.14329761, 0.02913095)
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_kcr48"]
|
||||||
|
points = PackedVector3Array(0.26999125, -0.058616668, -0.03817381, 0.28120872, 0.07599285, 0.02913095, 0.26999125, 0.07599285, 0.02913095, 0.28120872, -0.058616668, 0.02913095, 0.28120872, 0.07599285, -0.03817381, 0.26999125, 0.07599285, -0.03817381, 0.26999125, -0.058616668, 0.02913095, 0.28120872, -0.058616668, -0.03817381)
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_4nhs8"]
|
||||||
|
points = PackedVector3Array(0.06807698, -0.06983413, -0.03817381, 0.07929444, 0.08721031, 0.02913095, 0.06807698, 0.08721031, 0.02913095, 0.07929444, -0.06983413, 0.02913095, 0.07929444, 0.08721031, -0.03817381, 0.06807698, 0.08721031, -0.03817381, 0.06807698, -0.06983413, 0.02913095, 0.07929444, -0.06983413, -0.03817381)
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_k8bjv"]
|
||||||
|
points = PackedVector3Array(0.056859523, 0.019900061, -0.026956353, 0.06807589, 0.05354915, 0.01791349, 0.06807589, 0.06477539, 0.0066960296, 0.06807589, -0.036181748, -0.015734501, 0.056859523, -0.036181748, 0.01791349, 0.056859523, 0.05354915, 0.01791349, 0.06807589, -0.036181748, 0.01791349, 0.06807589, 0.019900061, -0.026956353, 0.056859523, -0.036181748, -0.015734501, 0.056859523, 0.06477539, -0.0045214314, 0.06807589, 0.05354915, -0.015734501, 0.056859523, 0.05354915, -0.015734501, 0.06807589, 0.008703465, -0.026956353)
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_thc0q"]
|
||||||
|
points = PackedVector3Array(-0.089002594, -0.047399208, 0.029121067, -0.27966428, 0.0647721, -0.015725713, -0.089002594, -0.013724867, -0.06060873, -0.27966428, -0.013724867, 0.051562577, -0.27966428, -0.036178455, -0.026946466, 0.056859523, -0.0025161915, 0.029121067, -0.089002594, 0.031121913, 0.06278333, 0.056859523, -0.036178455, -0.015725713, 0.056859523, 0.0647721, -0.0045170374, -0.089002594, 0.04233059, -0.06060873, -0.27966428, 0.053551342, 0.040329743, -0.27966428, 0.031121913, -0.049387977, -0.055337038, -0.036178455, 0.051562577, -0.089002594, 0.07599285, 0.017900314, -0.089002594, -0.047399208, -0.026946466, 0.056859523, 0.031121913, -0.026946466, -0.089002594, 0.07599285, -0.015725713, -0.27966428, -0.036178455, 0.029121067, 0.02319397, 0.053551342, 0.029121067, -0.27966428, -0.013724867, -0.049387977, -0.089002594, -0.036178455, -0.049387977, 0.056859523, -0.036178455, 0.017900314, -0.089002594, 0.053551342, 0.051562577, -0.089002594, -0.013724867, 0.06278333, -0.27966428, 0.053551342, -0.038155142, -0.27966428, 0.031121913, 0.051562577, -0.089002594, 0.0647721, -0.038155142, 0.056859523, -0.013724867, -0.026946466, -0.27966428, 0.0647721, 0.017900314, 0.034393862, 0.053551342, -0.026946466, 0.056859523, 0.0647721, 0.0066916384, -0.089002594, 0.0647721, 0.040329743)
|
||||||
|
|
||||||
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_3cvvy"]
|
||||||
|
points = PackedVector3Array(-0.27967966, 0.06477541, 0.017897021, -0.4367087, -0.036221273, -0.026948664, -0.4367087, -0.036221273, 0.029113382, -0.38060492, -0.17079127, -0.026948664, -0.27967966, 0.031086784, -0.04939127, -0.27967966, -0.013785254, 0.05156587, -0.4367087, 0.06477541, 0.017897021, -0.4367087, 0.031086784, -0.04939127, -0.41959414, -0.16049999, 0.016428277, -0.4367087, 0.031086784, 0.05156587, -0.2909004, -0.08104719, -0.026948664, -0.38060492, -0.17079127, 0.017897021, -0.42547256, -0.17079127, -0.026948664, -0.4367087, 0.05354586, -0.038165025, -0.27967966, -0.013785254, -0.04939127, -0.4367087, -0.013785254, 0.05156587, -0.27967966, 0.05354586, 0.040339626, -0.27967966, 0.06477541, -0.015732301, -0.2909004, -0.08104719, 0.017897021, -0.4367087, -0.013785254, -0.04939127, -0.3245473, -0.12591924, -0.026948664, -0.27967966, 0.031086784, 0.05156587, -0.4367087, 0.05354586, 0.040339626, -0.27967966, 0.05354586, -0.038165025, -0.4367087, 0.06477541, -0.015732301, -0.27967966, -0.036221273, -0.026948664, -0.27967966, -0.036221273, 0.029113382)
|
||||||
|
|
||||||
|
[node name="SimpleKey" type="Node3D" unique_id=650555678 node_paths=PackedStringArray("body", "snapAnchor", "visualMeshNode")]
|
||||||
script = ExtResource("1_rsor3")
|
script = ExtResource("1_rsor3")
|
||||||
body = NodePath("RigidBody3D")
|
body = NodePath("RigidBody3D")
|
||||||
snapAnchor = NodePath("RigidBody3D/SnapAnchor")
|
snapAnchor = NodePath("RigidBody3D/SnapAnchor")
|
||||||
|
visualMeshNode = NodePath("RigidBody3D/MeshInstance3D")
|
||||||
metadata/_custom_type_script = "uid://b143brnl7gf4f"
|
metadata/_custom_type_script = "uid://b143brnl7gf4f"
|
||||||
|
|
||||||
[node name="RigidBody3D" type="RigidBody3D" parent="." unique_id=1946674219]
|
[node name="RigidBody3D" type="RigidBody3D" parent="." unique_id=1946674219]
|
||||||
collision_layer = 9
|
collision_layer = 9
|
||||||
collision_mask = 13
|
collision_mask = 13
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D" unique_id=1252834786]
|
|
||||||
shape = SubResource("BoxShape3D_1blfk")
|
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D" unique_id=2082673006]
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D" unique_id=2082673006]
|
||||||
mesh = SubResource("BoxMesh_va8t4")
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
mesh = ExtResource("2_w4i4f")
|
||||||
surface_material_override/0 = SubResource("StandardMaterial3D_w4i4f")
|
surface_material_override/0 = SubResource("StandardMaterial3D_w4i4f")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D8" type="CollisionShape3D" parent="RigidBody3D" unique_id=668361815]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_w4i4f")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D7" type="CollisionShape3D" parent="RigidBody3D" unique_id=254679764]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_ycjx8")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D6" type="CollisionShape3D" parent="RigidBody3D" unique_id=1906243872]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_qtgaf")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D5" type="CollisionShape3D" parent="RigidBody3D" unique_id=1650561327]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_kcr48")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D4" type="CollisionShape3D" parent="RigidBody3D" unique_id=957277933]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_4nhs8")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D3" type="CollisionShape3D" parent="RigidBody3D" unique_id=790605504]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_k8bjv")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D2" type="CollisionShape3D" parent="RigidBody3D" unique_id=218214800]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_thc0q")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D" unique_id=1906805590]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, -0.06127593)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_3cvvy")
|
||||||
|
|
||||||
[node name="SnapAnchor" type="Marker3D" parent="RigidBody3D" unique_id=389082687]
|
[node name="SnapAnchor" type="Marker3D" parent="RigidBody3D" unique_id=389082687]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.15)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00036647916, 0, -0.27831292)
|
||||||
|
|||||||
+19
-12
@@ -1,26 +1,33 @@
|
|||||||
[gd_scene format=3 uid="uid://cvipcpeglasek"]
|
[gd_scene format=3 uid="uid://cvipcpeglasek"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://xd03vepkva1l" path="res://Scripts/Socket.gd" id="1_5ldhx"]
|
[ext_resource type="Script" uid="uid://xd03vepkva1l" path="res://Scripts/Socket.gd" id="1_5ldhx"]
|
||||||
|
[ext_resource type="Material" uid="uid://cgv3rv0ll5vul" path="res://Materials/HologramMaterial.tres" id="2_phqk8"]
|
||||||
|
[ext_resource type="ArrayMesh" uid="uid://c1turkdbdf672" path="res://Meshes/LockMesh.tres" id="2_xuv5d"]
|
||||||
|
|
||||||
[sub_resource type="BoxMesh" id="BoxMesh_1blfk"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_phqk8"]
|
||||||
size = Vector3(1, 1, 0.2)
|
albedo_color = Color(1, 0.6627451, 0.27450982, 1)
|
||||||
|
|
||||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1blfk"]
|
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_xuv5d"]
|
||||||
size = Vector3(1, 1, 0.2)
|
points = PackedVector3Array(-0.27519998, -0.8941344, -0.2593403, 0.26456764, 0.027564, 0.9763753, -0.24300638, 0.02218617, 0.99558824, 0.15747233, 1.5342898, -0.27855548, 0.26650333, -0.4031767, -0.8864768, -0.2739767, 0.41260198, -0.8711741, -0.1721238, 1.410366, 0.42174292, 0.2675441, -0.9146684, 0.322574, -0.2431448, -0.68814415, 0.71976835, 0.26387632, 0.33631924, -0.91568136, 0.15747233, 1.3693162, 0.50403607, -0.2442107, -0.29608637, -0.9411231, -0.1721238, 1.2867005, -0.48449, -0.27519998, 0.37477624, 0.89426947, 0.28552645, 0.5883212, -0.46201938, 0.26729187, -0.8742861, -0.4199976, 0.32236114, -0.23756212, -0.6906262, 0.2668279, -0.36496803, 0.9069698, -0.27025545, 0.94044054, -0.17905393, 0.25967497, 0.904319, 0.3887875, -0.24515258, -0.97439086, 0.12878603, -0.27519998, -0.701846, -0.6439396, -0.1721238, 1.5342898, 0.21560669, 0.15747233, 1.2867005, -0.52583826, 0.26116356, 0.41213495, 0.886924, -0.27519998, -0.3555823, 0.89426947, 0.15747233, 1.5755978, 0.21560669, -0.1721238, 1.5342898, -0.1549141, -0.24200568, 0.33703282, -0.9329809, 0.3042074, -0.74898386, 0.12586175, 0.26596537, -0.0906211, -0.9624079, 0.26534107, -0.7102548, 0.6689699)
|
||||||
|
|
||||||
[node name="SimpleSocket" type="Node3D" unique_id=1835661048 node_paths=PackedStringArray("snapPoint", "snapArea")]
|
[node name="SimpleSocket" type="Node3D" unique_id=1835661048 node_paths=PackedStringArray("snapPoint", "snapArea")]
|
||||||
|
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
|
||||||
script = ExtResource("1_5ldhx")
|
script = ExtResource("1_5ldhx")
|
||||||
snapPoint = NodePath("Marker3D")
|
snapPoint = NodePath("Marker3D")
|
||||||
snapArea = NodePath("Area3D")
|
snapArea = NodePath("Area3D")
|
||||||
metadata/_custom_type_script = "uid://xd03vepkva1l"
|
snapDistance = 2.0
|
||||||
|
hologramMaterial = ExtResource("2_phqk8")
|
||||||
|
|
||||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=1351826322]
|
[node name="Area3D" type="Area3D" parent="." unique_id=182097832]
|
||||||
mesh = SubResource("BoxMesh_1blfk")
|
|
||||||
|
|
||||||
[node name="Area3D" type="Area3D" parent="." unique_id=792436256]
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="Area3D" unique_id=1460440288]
|
||||||
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, 0)
|
||||||
|
mesh = ExtResource("2_xuv5d")
|
||||||
|
surface_material_override/0 = SubResource("StandardMaterial3D_phqk8")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D" unique_id=1932740275]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D" unique_id=893677199]
|
||||||
shape = SubResource("BoxShape3D_1blfk")
|
transform = Transform3D(-2.1855694e-08, 0, -0.5, 0, 0.5, 0, 0.5, 0, -2.1855694e-08, 0, 0, 0)
|
||||||
|
shape = SubResource("ConvexPolygonShape3D_xuv5d")
|
||||||
|
|
||||||
[node name="Marker3D" type="Marker3D" parent="." unique_id=1726119799]
|
[node name="Marker3D" type="Marker3D" parent="." unique_id=1828909901]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.1)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0037084222, -0.27249002, 0.154115)
|
||||||
|
|||||||
+10
-4
@@ -14,6 +14,7 @@ class_name Pickupable
|
|||||||
@export var maxDistance: float = 4.0
|
@export var maxDistance: float = 4.0
|
||||||
@export var body: RigidBody3D
|
@export var body: RigidBody3D
|
||||||
@export var snapAnchor: Marker3D
|
@export var snapAnchor: Marker3D
|
||||||
|
@export var visualMeshNode: MeshInstance3D
|
||||||
|
|
||||||
@export_range(0.01, 1000.0, 0.01) var bodyMass: float = 1.0
|
@export_range(0.01, 1000.0, 0.01) var bodyMass: float = 1.0
|
||||||
|
|
||||||
@@ -43,7 +44,15 @@ func beginInteract(player, hitPosition: Vector3):
|
|||||||
func updateInteract(player):
|
func updateInteract(player):
|
||||||
if !dragging:
|
if !dragging:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("action") and currentSocket != null:
|
||||||
|
if currentSocket.attachedObject == self:
|
||||||
|
currentSocket.detachObject()
|
||||||
|
else:
|
||||||
|
if currentSocket.attachObject(self):
|
||||||
|
endInteract(player)
|
||||||
|
return
|
||||||
|
|
||||||
body.sleeping = false
|
body.sleeping = false
|
||||||
|
|
||||||
# Toggle rotation mode
|
# Toggle rotation mode
|
||||||
@@ -117,9 +126,6 @@ func endInteract(player):
|
|||||||
rotating = false
|
rotating = false
|
||||||
player.setMouseFactors(1.0, 1.0)
|
player.setMouseFactors(1.0, 1.0)
|
||||||
playerRef = null
|
playerRef = null
|
||||||
|
|
||||||
if currentSocket != null and currentSocket.isInRange(self):
|
|
||||||
currentSocket.snapObject(self)
|
|
||||||
|
|
||||||
func throw():
|
func throw():
|
||||||
if !dragging:
|
if !dragging:
|
||||||
|
|||||||
+61
-35
@@ -5,68 +5,94 @@ extends Node3D
|
|||||||
@export var snapArea: Area3D
|
@export var snapArea: Area3D
|
||||||
@export var snapDistance: float = 0.5
|
@export var snapDistance: float = 0.5
|
||||||
@export var lockOnSnap: bool = true
|
@export var lockOnSnap: bool = true
|
||||||
|
@export var hologramMaterial: Material
|
||||||
|
|
||||||
|
var hologramInstance: MeshInstance3D
|
||||||
var candidate: Pickupable = null
|
var candidate: Pickupable = null
|
||||||
var snappedObject: Pickupable = null
|
var attachedObject: Pickupable = null
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
if snapArea:
|
if snapArea:
|
||||||
snapArea.body_entered.connect(onBodyEntered)
|
snapArea.body_entered.connect(onBodyEntered)
|
||||||
snapArea.body_exited.connect(onBodyExited)
|
snapArea.body_exited.connect(onBodyExited)
|
||||||
|
|
||||||
|
hologramInstance = MeshInstance3D.new()
|
||||||
|
hologramInstance.top_level = true
|
||||||
|
hologramInstance.visible = false
|
||||||
|
|
||||||
|
if hologramMaterial:
|
||||||
|
hologramInstance.material_override = hologramMaterial
|
||||||
|
|
||||||
|
add_child(hologramInstance)
|
||||||
|
|
||||||
func isInRange(object: Pickupable) -> bool:
|
func canAttach(object: Pickupable) -> bool:
|
||||||
if object == null:
|
if attachedObject != null:
|
||||||
return false
|
return false
|
||||||
|
if object == null or object.snapAnchor == null:
|
||||||
if object.snapAnchor == null:
|
|
||||||
return false
|
return false
|
||||||
|
var distance := object.snapAnchor.global_position.distance_to(snapPoint.global_position)
|
||||||
var distance := object.snapAnchor.global_position.distance_to(
|
|
||||||
snapPoint.global_position
|
|
||||||
)
|
|
||||||
|
|
||||||
return distance <= snapDistance
|
return distance <= snapDistance
|
||||||
|
|
||||||
|
func attachObject(object: Pickupable) -> bool:
|
||||||
|
if not canAttach(object):
|
||||||
|
return false
|
||||||
|
|
||||||
|
var targetTransform := getSnapTransform(object)
|
||||||
|
var body := object.body
|
||||||
|
body.linear_velocity = Vector3.ZERO
|
||||||
|
body.angular_velocity = Vector3.ZERO
|
||||||
|
body.global_transform = targetTransform
|
||||||
|
|
||||||
|
if lockOnSnap:
|
||||||
|
body.freeze = true
|
||||||
|
|
||||||
|
attachedObject = object
|
||||||
|
candidate = null
|
||||||
|
object.currentSocket = self
|
||||||
|
|
||||||
|
if hologramInstance:
|
||||||
|
hologramInstance.visible = false
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
func detachObject() -> void:
|
||||||
|
if attachedObject == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
var body := attachedObject.body
|
||||||
|
if lockOnSnap:
|
||||||
|
body.freeze = false
|
||||||
|
|
||||||
|
attachedObject.currentSocket = null
|
||||||
|
attachedObject = null
|
||||||
|
|
||||||
func getSnapTransform(object: Pickupable) -> Transform3D:
|
func getSnapTransform(object: Pickupable) -> Transform3D:
|
||||||
var objectTransform := object.body.global_transform
|
var objectTransform := object.body.global_transform
|
||||||
var anchorTransform := object.snapAnchor.global_transform
|
var anchorTransform := object.snapAnchor.global_transform
|
||||||
|
|
||||||
# Where is the SnapAnchor relative to the Rigidbody?
|
|
||||||
var anchorOffset := objectTransform.affine_inverse() * anchorTransform
|
var anchorOffset := objectTransform.affine_inverse() * anchorTransform
|
||||||
|
|
||||||
# We want the SnapAnchor to have exactly the same
|
|
||||||
# transform as the Socket's SnapPoint.
|
|
||||||
return snapPoint.global_transform * anchorOffset.affine_inverse()
|
return snapPoint.global_transform * anchorOffset.affine_inverse()
|
||||||
|
|
||||||
func snapObject(object: Pickupable):
|
|
||||||
if not isInRange(object):
|
|
||||||
return
|
|
||||||
|
|
||||||
var targetTransform := getSnapTransform(object)
|
|
||||||
|
|
||||||
var body := object.body
|
|
||||||
|
|
||||||
body.linear_velocity = Vector3.ZERO
|
|
||||||
body.angular_velocity = Vector3.ZERO
|
|
||||||
|
|
||||||
body.global_transform = targetTransform
|
|
||||||
|
|
||||||
if lockOnSnap:
|
|
||||||
body.freeze = true
|
|
||||||
|
|
||||||
snappedObject = object
|
|
||||||
candidate = null
|
|
||||||
|
|
||||||
func onBodyEntered(body: Node3D):
|
func onBodyEntered(body: Node3D):
|
||||||
|
if attachedObject != null: return
|
||||||
if body is RigidBody3D and body.get_parent() is Pickupable:
|
if body is RigidBody3D and body.get_parent() is Pickupable:
|
||||||
var pickup = body.get_parent() as Pickupable
|
var pickup = body.get_parent() as Pickupable
|
||||||
pickup.currentSocket = self
|
pickup.currentSocket = self
|
||||||
candidate = pickup
|
candidate = pickup
|
||||||
|
|
||||||
|
if pickup.visualMeshNode and pickup.visualMeshNode.mesh:
|
||||||
|
hologramInstance.mesh = pickup.visualMeshNode.mesh
|
||||||
|
var targetBodyTransform = getSnapTransform(pickup)
|
||||||
|
var meshLocalTranform = pickup.body.global_transform.affine_inverse() * pickup.visualMeshNode.global_transform
|
||||||
|
hologramInstance.global_transform = targetBodyTransform * meshLocalTranform
|
||||||
|
hologramInstance.visible = true
|
||||||
|
|
||||||
func onBodyExited(body: Node3D):
|
func onBodyExited(body: Node3D):
|
||||||
if body is RigidBody3D and body.get_parent() is Pickupable:
|
if body is RigidBody3D and body.get_parent() is Pickupable:
|
||||||
var pickup = body.get_parent() as Pickupable
|
var pickup = body.get_parent() as Pickupable
|
||||||
if pickup.currentSocket == self:
|
if pickup.currentSocket == self and attachedObject != pickup:
|
||||||
pickup.currentSocket = null
|
pickup.currentSocket = null
|
||||||
if candidate == pickup:
|
if candidate == pickup:
|
||||||
candidate = null
|
candidate = null
|
||||||
|
|
||||||
|
if hologramInstance:
|
||||||
|
hologramInstance.visible = false
|
||||||
|
|||||||
+6
-2
@@ -49,8 +49,7 @@ jump={
|
|||||||
}
|
}
|
||||||
interact={
|
interact={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(159, 9),"global_position":Vector2(168, 57),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||||
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(159, 9),"global_position":Vector2(168, 57),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
throw={
|
throw={
|
||||||
@@ -63,6 +62,11 @@ rotate={
|
|||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
action={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user