Created first version of SimpleSocket to test socket with SimpleKey (Any pickupable with socket)
This commit is contained in:
+5
-2
@@ -1,5 +1,6 @@
|
||||
[gd_scene format=3 uid="uid://cwwsolupah1s3"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cvipcpeglasek" path="res://Scenes/SimpleSocket.tscn" id="1_grg3l"]
|
||||
[ext_resource type="PackedScene" uid="uid://cpog4xqme7wqj" path="res://Scenes/Player.tscn" id="1_pbw6q"]
|
||||
[ext_resource type="PackedScene" uid="uid://hmpweoahtner" path="res://Scenes/Door.tscn" id="2_v1gob"]
|
||||
[ext_resource type="PackedScene" uid="uid://dgre5brxnbps0" path="res://Scenes/MedievalDoor.tscn" id="3_jw32o"]
|
||||
@@ -41,6 +42,9 @@ mesh = SubResource("BoxMesh_1blfk")
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" unique_id=2109163521]
|
||||
shape = SubResource("BoxShape3D_va8t4")
|
||||
|
||||
[node name="SimpleSocket" parent="StaticBody3D" unique_id=1835661048 instance=ExtResource("1_grg3l")]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.6742996, 0.7384579, 0, -0.7384579, 0.6742996, -11.95581, 1.1145909, 3.0031586)
|
||||
|
||||
[node name="Player" parent="." unique_id=1270645855 instance=ExtResource("1_pbw6q")]
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=1880837933]
|
||||
@@ -126,10 +130,9 @@ maxRaycastDistance = 10.0
|
||||
[node name="SimplePickupable4" parent="." unique_id=1419866814 instance=ExtResource("10_bmxlf")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.0351448, 3.2192059)
|
||||
|
||||
[node name="SimplePickupable5" type="Node3D" parent="." unique_id=1116791131 node_paths=PackedStringArray("body")]
|
||||
[node name="SimplePickupable5" type="Node3D" parent="." unique_id=1116791131]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.0500765, 1.2124488, 6.335041)
|
||||
script = ExtResource("11_4kpch")
|
||||
body = NodePath("")
|
||||
bodyMass = 100.0
|
||||
metadata/_custom_type_script = "uid://b143brnl7gf4f"
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ albedo_color = Color(1, 1, 0, 1)
|
||||
[node name="SimpleKey" type="Node3D" unique_id=650555678 node_paths=PackedStringArray("body", "snapAnchor")]
|
||||
script = ExtResource("1_rsor3")
|
||||
body = NodePath("RigidBody3D")
|
||||
snapAnchor = NodePath("SnapAnchor")
|
||||
snapAnchor = NodePath("RigidBody3D/SnapAnchor")
|
||||
metadata/_custom_type_script = "uid://b143brnl7gf4f"
|
||||
|
||||
[node name="RigidBody3D" type="RigidBody3D" parent="." unique_id=1946674219]
|
||||
@@ -28,5 +28,5 @@ shape = SubResource("BoxShape3D_1blfk")
|
||||
mesh = SubResource("BoxMesh_va8t4")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_w4i4f")
|
||||
|
||||
[node name="SnapAnchor" type="Marker3D" parent="." unique_id=389082687]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.15)
|
||||
[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)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
[gd_scene format=3 uid="uid://cvipcpeglasek"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://xd03vepkva1l" path="res://Scripts/Socket.gd" id="1_5ldhx"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_1blfk"]
|
||||
size = Vector3(1, 1, 0.2)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1blfk"]
|
||||
size = Vector3(1, 1, 0.2)
|
||||
|
||||
[node name="SimpleSocket" type="Node3D" unique_id=1835661048 node_paths=PackedStringArray("snapPoint", "snapArea")]
|
||||
script = ExtResource("1_5ldhx")
|
||||
snapPoint = NodePath("Marker3D")
|
||||
snapArea = NodePath("Area3D")
|
||||
metadata/_custom_type_script = "uid://xd03vepkva1l"
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=1351826322]
|
||||
mesh = SubResource("BoxMesh_1blfk")
|
||||
|
||||
[node name="Area3D" type="Area3D" parent="." unique_id=792436256]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D" unique_id=1932740275]
|
||||
shape = SubResource("BoxShape3D_1blfk")
|
||||
|
||||
[node name="Marker3D" type="Marker3D" parent="." unique_id=1726119799]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.1)
|
||||
@@ -25,6 +25,8 @@ var holdDistance: float
|
||||
var rotationOffset: Basis
|
||||
var localCenterOffset: Vector3
|
||||
|
||||
var currentSocket: Socket = null
|
||||
|
||||
func _ready():
|
||||
if body:
|
||||
body.mass = bodyMass
|
||||
@@ -115,6 +117,9 @@ func endInteract(player):
|
||||
rotating = false
|
||||
player.setMouseFactors(1.0, 1.0)
|
||||
playerRef = null
|
||||
|
||||
if currentSocket != null and currentSocket.isInRange(self):
|
||||
currentSocket.snapObject(self)
|
||||
|
||||
func throw():
|
||||
if !dragging:
|
||||
|
||||
+22
-2
@@ -2,13 +2,19 @@ class_name Socket
|
||||
extends Node3D
|
||||
|
||||
@export var snapPoint: Marker3D
|
||||
@export var snapArea: Area3D
|
||||
@export var snapDistance: float = 0.5
|
||||
@export var lockOnSnap: bool = true
|
||||
|
||||
var candidate: Pickupable = null
|
||||
var snappedObject: Pickupable = null
|
||||
|
||||
func is_in_range(object: Pickupable) -> bool:
|
||||
func _ready() -> void:
|
||||
if snapArea:
|
||||
snapArea.body_entered.connect(onBodyEntered)
|
||||
snapArea.body_exited.connect(onBodyExited)
|
||||
|
||||
func isInRange(object: Pickupable) -> bool:
|
||||
if object == null:
|
||||
return false
|
||||
|
||||
@@ -33,7 +39,7 @@ func getSnapTransform(object: Pickupable) -> Transform3D:
|
||||
return snapPoint.global_transform * anchorOffset.affine_inverse()
|
||||
|
||||
func snapObject(object: Pickupable):
|
||||
if not is_in_range(object):
|
||||
if not isInRange(object):
|
||||
return
|
||||
|
||||
var targetTransform := getSnapTransform(object)
|
||||
@@ -50,3 +56,17 @@ func snapObject(object: Pickupable):
|
||||
|
||||
snappedObject = object
|
||||
candidate = null
|
||||
|
||||
func onBodyEntered(body: Node3D):
|
||||
if body is RigidBody3D and body.get_parent() is Pickupable:
|
||||
var pickup = body.get_parent() as Pickupable
|
||||
pickup.currentSocket = self
|
||||
candidate = pickup
|
||||
|
||||
func onBodyExited(body: Node3D):
|
||||
if body is RigidBody3D and body.get_parent() is Pickupable:
|
||||
var pickup = body.get_parent() as Pickupable
|
||||
if pickup.currentSocket == self:
|
||||
pickup.currentSocket = null
|
||||
if candidate == pickup:
|
||||
candidate = null
|
||||
|
||||
Reference in New Issue
Block a user