Resolved interaction system
This commit is contained in:
parent
72bea66082
commit
22cdc782f9
9 changed files with 96 additions and 73 deletions
|
|
@ -7,10 +7,10 @@ const SENSITIVITY = 0.01
|
|||
var interaction_source: DraggableObject
|
||||
var plane_position: Vector3
|
||||
@onready var drag_raycast: RayCast3D = $DragRaycast
|
||||
@onready var interaction_area: InteractibleDetector = $InteractionArea
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
drag_raycast.target_position = project_local_ray_normal(get_viewport().get_mouse_position()) * 10.0
|
||||
var ray_normal = project_local_ray_normal(get_viewport().get_mouse_position())
|
||||
drag_raycast.target_position = ray_normal * 10.0
|
||||
if drag_raycast.is_colliding():
|
||||
plane_position = drag_raycast.get_collision_point()
|
||||
|
||||
|
|
@ -19,8 +19,8 @@ func _input(event: InputEvent) -> void:
|
|||
global_position -= Vector3.RIGHT * event.relative.x * SENSITIVITY
|
||||
global_position += Vector3.FORWARD * event.relative.y * SENSITIVITY
|
||||
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
for draggable in interaction_area.filtered_draggables:
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed and interaction_source != null:
|
||||
for draggable in interaction_source.filtered_draggables:
|
||||
if draggable == interaction_source:
|
||||
continue
|
||||
interaction_source.interactible.try_interact(draggable)
|
||||
|
|
@ -31,7 +31,6 @@ 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:
|
||||
|
|
|
|||
|
|
@ -18,12 +18,27 @@ var dragged: bool = false:
|
|||
|
||||
@export var interactible: Interactible
|
||||
|
||||
@export var mask: PackedStringArray
|
||||
var contacted_draggables: Array[DraggableObject]
|
||||
var filtered_draggables: Array[DraggableObject]
|
||||
|
||||
func _ready() -> void:
|
||||
area_entered.connect(on_area_entered)
|
||||
area_exited.connect(on_area_exited)
|
||||
|
||||
func _mouse_enter() -> void:
|
||||
mouse_in = true
|
||||
|
||||
func _mouse_exit() -> void:
|
||||
mouse_in = false
|
||||
|
||||
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 _process(_delta: float) -> void:
|
||||
if dragged == false:
|
||||
return
|
||||
|
|
@ -36,3 +51,21 @@ func _input(event: InputEvent) -> void:
|
|||
dragged = true
|
||||
if event.pressed == false:
|
||||
dragged = false
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ extends ConfirmationDialog
|
|||
|
||||
class_name Interactible
|
||||
|
||||
@export var interaction_target_groups: PackedStringArray
|
||||
@export var instant: bool = false
|
||||
|
||||
var current_draggable: DraggableObject
|
||||
|
|
@ -15,18 +14,14 @@ func _ready() -> void:
|
|||
confirmed.connect(interact)
|
||||
canceled.connect(cancel_interaction)
|
||||
|
||||
func try_interact(draggable: DraggableObject) -> void:
|
||||
if draggable.interactible != null:
|
||||
var interaction: Interactible = draggable.interactible
|
||||
for group in interaction.get_groups():
|
||||
if group in interaction_target_groups:
|
||||
current_draggable = draggable
|
||||
current_interaction = interaction
|
||||
if instant:
|
||||
interact()
|
||||
else:
|
||||
popup_centered()
|
||||
break
|
||||
func try_interact(draggable: DraggableObject) -> bool:
|
||||
if draggable.interactible != null and visible == false:
|
||||
if instant:
|
||||
interact()
|
||||
else:
|
||||
popup_centered()
|
||||
return true
|
||||
return false
|
||||
|
||||
func interact():
|
||||
interacted.emit(current_draggable)
|
||||
|
|
|
|||
|
|
@ -1,37 +1,3 @@
|
|||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -9,3 +9,6 @@ func _ready() -> void:
|
|||
jar_fill_material.albedo_color = substance.color
|
||||
if substance.melting_point > 20 and not substance.is_solution:
|
||||
jar_fill_material.albedo_texture = preload("res://assets/textures/solid.png")
|
||||
get_parent().add_to_group("solid_source")
|
||||
else:
|
||||
get_parent().add_to_group("fluid_source")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue