Interaction rework
This commit is contained in:
parent
345acc8079
commit
72bea66082
11 changed files with 90 additions and 23 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
[gd_scene load_steps=3 format=3 uid="uid://c2vxq6kqhris0"]
|
[gd_scene load_steps=4 format=3 uid="uid://b8edjit66j7st"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://crjao0jjv5yqs" path="res://src/drag/draggable_camera.gd" id="1_v4apc"]
|
[ext_resource type="Script" uid="uid://crjao0jjv5yqs" path="res://src/drag/draggable_camera.gd" id="1_v4apc"]
|
||||||
|
[ext_resource type="Script" uid="uid://d77lra3ar60b" path="res://src/interactible/interactible_detector.gd" id="2_nstyr"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_hflkp"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_hflkp"]
|
||||||
radius = 0.1
|
radius = 0.1
|
||||||
|
|
@ -16,6 +17,7 @@ target_position = Vector3(0, 0, -10)
|
||||||
[node name="InteractionArea" type="Area3D" parent="."]
|
[node name="InteractionArea" type="Area3D" parent="."]
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
collision_mask = 4
|
collision_mask = 4
|
||||||
|
script = ExtResource("2_nstyr")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractionArea"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="InteractionArea"]
|
||||||
transform = Transform3D(1, 0, 0, 0, -2.9802322e-08, -1, 0, 1, -2.9802322e-08, 0, 3.5762787e-07, -5.2500005)
|
transform = Transform3D(1, 0, 0, 0, -2.9802322e-08, -1, 0, 1, -2.9802322e-08, 0, 3.5762787e-07, -5.2500005)
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,18 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://bjxjcx2qu16q5"]
|
[gd_scene load_steps=6 format=3 uid="uid://bjxjcx2qu16q5"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bjnv2g1ni0525" path="res://src/drag/draggable_object.gd" id="1_0xufn"]
|
[ext_resource type="Script" uid="uid://bjnv2g1ni0525" path="res://src/drag/draggable_object.gd" id="1_0xufn"]
|
||||||
[ext_resource type="PackedScene" uid="uid://b6ydpkle2ol20" path="res://assets/models/FlaskNew.glb" id="2_h7awq"]
|
[ext_resource type="PackedScene" uid="uid://b6ydpkle2ol20" path="res://assets/models/FlaskNew.glb" id="2_h7awq"]
|
||||||
|
[ext_resource type="Script" uid="uid://bl0ojhc0thk1p" path="res://src/interactible/interactible.gd" id="4_dbm1u"]
|
||||||
[ext_resource type="Script" uid="uid://82ettbegollp" path="res://src/inventory.gd" id="7_h7awq"]
|
[ext_resource type="Script" uid="uid://82ettbegollp" path="res://src/inventory.gd" id="7_h7awq"]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_vcwhe"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_vcwhe"]
|
||||||
radius = 0.1
|
radius = 0.1
|
||||||
height = 0.9921875
|
height = 0.9921875
|
||||||
|
|
||||||
[node name="Flask" type="Area3D"]
|
[node name="Flask" type="Area3D" node_paths=PackedStringArray("interactible")]
|
||||||
collision_layer = 5
|
collision_layer = 5
|
||||||
script = ExtResource("1_0xufn")
|
script = ExtResource("1_0xufn")
|
||||||
|
interactible = NodePath("Interactible")
|
||||||
|
|
||||||
[node name="DragArea" type="CollisionShape3D" parent="."]
|
[node name="DragArea" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||||
|
|
@ -24,3 +26,7 @@ unique_name_in_owner = true
|
||||||
script = ExtResource("7_h7awq")
|
script = ExtResource("7_h7awq")
|
||||||
open_on_top = true
|
open_on_top = true
|
||||||
metadata/_custom_type_script = "uid://82ettbegollp"
|
metadata/_custom_type_script = "uid://82ettbegollp"
|
||||||
|
|
||||||
|
[node name="Interactible" type="ConfirmationDialog" parent="."]
|
||||||
|
script = ExtResource("4_dbm1u")
|
||||||
|
interaction_target_groups = PackedStringArray("test")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[gd_scene load_steps=5 format=3 uid="uid://q1y0r2rn0qb4"]
|
[gd_scene load_steps=5 format=3 uid="uid://q1y0r2rn0qb4"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://mjx50qh1bwv3" path="res://src/interactible/interaction_reciever.gd" id="1_auicg"]
|
[ext_resource type="Script" path="res://src/interactible/interaction_reciever.gd" id="1_auicg"]
|
||||||
[ext_resource type="Material" uid="uid://64m17act0kwu" path="res://assets/materials/mat_glass.tres" id="2_mqqtq"]
|
[ext_resource type="Material" uid="uid://64m17act0kwu" path="res://assets/materials/mat_glass.tres" id="2_mqqtq"]
|
||||||
|
|
||||||
[sub_resource type="CylinderMesh" id="CylinderMesh_nql6a"]
|
[sub_resource type="CylinderMesh" id="CylinderMesh_nql6a"]
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,10 @@ resource_local_to_scene = true
|
||||||
height = 0.5024414
|
height = 0.5024414
|
||||||
radius = 0.22460938
|
radius = 0.22460938
|
||||||
|
|
||||||
[node name="Flask" type="Area3D"]
|
[node name="Flask" type="Area3D" node_paths=PackedStringArray("interactible") groups=["test"]]
|
||||||
collision_layer = 5
|
collision_layer = 5
|
||||||
script = ExtResource("1_o7vug")
|
script = ExtResource("1_o7vug")
|
||||||
|
interactible = NodePath("Interaction")
|
||||||
|
|
||||||
[node name="Jar" type="MeshInstance3D" parent="."]
|
[node name="Jar" type="MeshInstance3D" parent="."]
|
||||||
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0)
|
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0)
|
||||||
|
|
@ -34,5 +35,4 @@ shape = SubResource("CylinderShape3D_kfk5m")
|
||||||
script = ExtResource("7_ymvgp")
|
script = ExtResource("7_ymvgp")
|
||||||
|
|
||||||
[node name="Interaction" type="ConfirmationDialog" parent="."]
|
[node name="Interaction" type="ConfirmationDialog" parent="."]
|
||||||
unique_name_in_owner = true
|
|
||||||
script = ExtResource("5_o7vug")
|
script = ExtResource("5_o7vug")
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
extends Camera3D
|
extends Camera3D
|
||||||
|
|
||||||
|
class_name DraggableCamera
|
||||||
|
|
||||||
const SENSITIVITY = 0.01
|
const SENSITIVITY = 0.01
|
||||||
|
|
||||||
var interaction_source: DraggableObject
|
var interaction_source: DraggableObject
|
||||||
var plane_position: Vector3
|
var plane_position: Vector3
|
||||||
@onready var drag_raycast: RayCast3D = $DragRaycast
|
@onready var drag_raycast: RayCast3D = $DragRaycast
|
||||||
@onready var interaction_area: Area3D = $InteractionArea
|
@onready var interaction_area: InteractibleDetector = $InteractionArea
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
drag_raycast.target_position = project_local_ray_normal(get_viewport().get_mouse_position()) * 10.0
|
drag_raycast.target_position = project_local_ray_normal(get_viewport().get_mouse_position()) * 10.0
|
||||||
|
|
@ -18,10 +20,21 @@ func _input(event: InputEvent) -> void:
|
||||||
global_position += Vector3.FORWARD * event.relative.y * SENSITIVITY
|
global_position += Vector3.FORWARD * event.relative.y * SENSITIVITY
|
||||||
|
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
var areas = interaction_area.get_overlapping_areas()
|
for draggable in interaction_area.filtered_draggables:
|
||||||
for area in areas:
|
if draggable == interaction_source:
|
||||||
if area == interaction_source:
|
|
||||||
continue
|
continue
|
||||||
area.try_interact(interaction_source)
|
interaction_source.interactible.try_interact(draggable)
|
||||||
break
|
break
|
||||||
|
end_interaction_seeking()
|
||||||
|
|
||||||
|
func start_interaction_seeking(new_interaction_source: DraggableObject) -> void:
|
||||||
|
if new_interaction_source.interactible == null:
|
||||||
|
return
|
||||||
|
interaction_source = new_interaction_source
|
||||||
|
interaction_area.set_mask(interaction_source.interactible.get_groups())
|
||||||
|
|
||||||
|
func end_interaction_seeking() -> void:
|
||||||
|
if interaction_source == null:
|
||||||
|
return
|
||||||
|
|
||||||
interaction_source = null
|
interaction_source = null
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,17 @@ signal drag_started
|
||||||
signal drag_ended
|
signal drag_ended
|
||||||
|
|
||||||
var mouse_in: bool = false
|
var mouse_in: bool = false
|
||||||
var dragged: bool = false
|
var dragged: bool = false:
|
||||||
|
set(value):
|
||||||
|
if dragged != value:
|
||||||
|
if value:
|
||||||
|
drag_started.emit()
|
||||||
|
get_viewport().get_camera_3d().start_interaction_seeking(self)
|
||||||
|
else:
|
||||||
|
drag_ended.emit()
|
||||||
|
dragged = value
|
||||||
|
|
||||||
|
@export var interactible: Interactible
|
||||||
|
|
||||||
func _mouse_enter() -> void:
|
func _mouse_enter() -> void:
|
||||||
mouse_in = true
|
mouse_in = true
|
||||||
|
|
@ -24,8 +34,5 @@ func _input(event: InputEvent) -> void:
|
||||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
if mouse_in and event.pressed:
|
if mouse_in and event.pressed:
|
||||||
dragged = true
|
dragged = true
|
||||||
drag_started.emit()
|
|
||||||
get_viewport().get_camera_3d().interaction_source = self
|
|
||||||
if event.pressed == false:
|
if event.pressed == false:
|
||||||
dragged = false
|
dragged = false
|
||||||
drag_ended.emit()
|
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ func _ready() -> void:
|
||||||
canceled.connect(cancel_interaction)
|
canceled.connect(cancel_interaction)
|
||||||
|
|
||||||
func try_interact(draggable: DraggableObject) -> void:
|
func try_interact(draggable: DraggableObject) -> void:
|
||||||
if draggable.get_node("%Interaction") != null:
|
if draggable.interactible != null:
|
||||||
var interaction: Interactible = draggable.get_node("%Interaction")
|
var interaction: Interactible = draggable.interactible
|
||||||
for group in interaction.get_groups():
|
for group in interaction.get_groups():
|
||||||
if group in interaction_target_groups:
|
if group in interaction_target_groups:
|
||||||
current_draggable = draggable
|
current_draggable = draggable
|
||||||
|
|
|
||||||
37
src/interactible/interactible_detector.gd
Normal file
37
src/interactible/interactible_detector.gd
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
extends Area3D
|
||||||
|
|
||||||
|
class_name InteractibleDetector
|
||||||
|
|
||||||
|
var mask: PackedStringArray
|
||||||
|
var contacted_draggables: Array[DraggableObject]
|
||||||
|
var filtered_draggables: Array[DraggableObject]
|
||||||
|
|
||||||
|
func set_mask(new_mask: PackedStringArray) -> void:
|
||||||
|
mask.clear()
|
||||||
|
mask.append_array(new_mask)
|
||||||
|
filtered_draggables.clear()
|
||||||
|
for contacted in contacted_draggables:
|
||||||
|
filtered_draggables.append(contacted)
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
area_entered.connect(on_area_entered)
|
||||||
|
area_exited.connect(on_area_exited)
|
||||||
|
|
||||||
|
func on_area_entered(area: Area3D) -> void:
|
||||||
|
if area is DraggableObject:
|
||||||
|
contacted_draggables.append(area)
|
||||||
|
if is_in_mask(area.get_groups()):
|
||||||
|
filtered_draggables.append(area)
|
||||||
|
|
||||||
|
func on_area_exited(area: Area3D) -> void:
|
||||||
|
if area is DraggableObject:
|
||||||
|
contacted_draggables.erase(area)
|
||||||
|
if filtered_draggables.has(area):
|
||||||
|
filtered_draggables.erase(area)
|
||||||
|
|
||||||
|
func is_in_mask(groups: Array[StringName]) -> bool:
|
||||||
|
for group in groups:
|
||||||
|
if group in mask:
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
1
src/interactible/interactible_detector.gd.uid
Normal file
1
src/interactible/interactible_detector.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d77lra3ar60b
|
||||||
|
|
@ -5,9 +5,9 @@ extends Button
|
||||||
|
|
||||||
func _on_button_down() -> void:
|
func _on_button_down() -> void:
|
||||||
var scene = draggable.scene_to_spawn.instantiate()
|
var scene = draggable.scene_to_spawn.instantiate()
|
||||||
|
get_tree().current_scene.add_child(scene)
|
||||||
if scene is DraggableObject:
|
if scene is DraggableObject:
|
||||||
scene.dragged = true
|
scene.dragged = true
|
||||||
scene.mouse_in = true
|
scene.mouse_in = true
|
||||||
get_tree().current_scene.add_child(scene)
|
|
||||||
var camera = get_viewport().get_camera_3d()
|
var camera = get_viewport().get_camera_3d()
|
||||||
scene.global_position = camera.project_position(get_global_mouse_position(),1.8)
|
scene.global_position = camera.plane_position
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,11 @@ func _ready() -> void:
|
||||||
|
|
||||||
func _on_button_down() -> void:
|
func _on_button_down() -> void:
|
||||||
var scene = reagent.storage.instantiate()
|
var scene = reagent.storage.instantiate()
|
||||||
|
|
||||||
|
scene.get_node("SubstanceData").substance = reagent.substance
|
||||||
|
get_tree().current_scene.add_child(scene)
|
||||||
if scene is DraggableObject:
|
if scene is DraggableObject:
|
||||||
scene.dragged = true
|
scene.dragged = true
|
||||||
scene.mouse_in = true
|
scene.mouse_in = true
|
||||||
scene.get_node("SubstanceData").substance = reagent.substance
|
|
||||||
get_tree().current_scene.add_child(scene)
|
|
||||||
var camera = get_viewport().get_camera_3d()
|
var camera = get_viewport().get_camera_3d()
|
||||||
scene.global_position = camera.project_position(get_global_mouse_position(),1.8)
|
scene.global_position = camera.plane_position
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue