fix movable and menu

This commit is contained in:
Nitwel 2024-04-25 19:09:52 +02:00
parent 5605934e03
commit 0433331e2b
4 changed files with 28 additions and 19 deletions

View File

@ -9,17 +9,26 @@ signal on_moved()
@export var restrict_movement: Callable
@export var lock_rotation: bool = false
var hit_node := Node3D.new()
var initiator = null
func _on_grab_down(event: EventPointer):
if restricted && event.target != get_parent():
if restricted&&event.target != get_parent():
return
event.initiator.node.add_child(hit_node)
initiator = event.initiator
if hit_node.get_parent() != null:
hit_node.get_parent().remove_child(hit_node)
initiator.node.add_child(hit_node)
hit_node.global_transform = get_parent().global_transform
func _on_grab_move(_event: EventPointer):
func _on_grab_move(event: EventPointer):
if hit_node.get_parent() == null:
return
if event.initiator != initiator:
return
if restrict_movement:
get_parent().global_position = restrict_movement.call(hit_node.global_position)
@ -33,7 +42,14 @@ func _on_grab_move(_event: EventPointer):
on_move.emit(get_parent().global_position, Vector3(0, 0, 0))
func _on_grab_up(event: EventPointer):
event.initiator.node.remove_child(hit_node)
if event.initiator != initiator:
return
if hit_node.get_parent() == null:
return
initiator = null
hit_node.get_parent().remove_child(hit_node)
on_moved.emit()
func _get_configuration_warnings() -> PackedStringArray:
@ -41,6 +57,5 @@ func _get_configuration_warnings() -> PackedStringArray:
if get_parent() is StaticBody3D == false:
warnings.append("Movable requires a StaticBody3D as parent.")
return warnings

View File

@ -122,12 +122,12 @@ func _process_hand(hand: OpenXRHand):
initiator.on_release.emit(Initiator.EventType.GRIP)
grabbed_left = false
else:
if trigger_close&&!grabbed_right:
if trigger_close&&!grabbed_left:
initiator.on_press.emit(Initiator.EventType.GRIP)
grabbed_right = true
elif !trigger_close&&grabbed_right:
grabbed_left = true
elif !trigger_close&&grabbed_left:
initiator.on_release.emit(Initiator.EventType.GRIP)
grabbed_right = false
grabbed_left = false
else:
if !distance_close:
if trigger_close&&!pressed_right:

View File

@ -45,7 +45,7 @@ outline_size = 0
autowrap_mode = 3
width = 40.0
[node name="FingerArea" type="Area3D" parent="."]
[node name="FingerArea" type="Area3D" parent="." groups=["ui_focus_skip"]]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.015)
collision_layer = 4
collision_mask = 0

View File

@ -188,8 +188,8 @@ _data = {
}
[node name="Menu" type="StaticBody3D"]
collision_layer = 2
collision_mask = 2
collision_layer = 6
collision_mask = 6
script = ExtResource("1_ng4u3")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
@ -199,14 +199,8 @@ shape = SubResource("BoxShape3D_e1esh")
[node name="Movable" type="Node" parent="."]
script = ExtResource("2_8coxu")
[node name="AnimationContainer" type="StaticBody3D" parent="."]
[node name="AnimationContainer" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.23, 0.15, 0)
collision_layer = 6
collision_mask = 6
[node name="CollisionShape3D" type="CollisionShape3D" parent="AnimationContainer"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.2, -0.15, -0.005)
shape = SubResource("BoxShape3D_e1esh")
[node name="Background" type="MeshInstance3D" parent="AnimationContainer"]
transform = Transform3D(1, 0, 0, 0, 1, 1.06581e-14, 0, -1.06581e-14, 1, 0.23, -0.15, 0)