des indices d'intéractions à base de shaders et de bulles

This commit is contained in:
Thomas
2025-03-19 17:13:57 +01:00
parent 65af087d46
commit 0b805448ee
19 changed files with 1616 additions and 44 deletions

View File

@@ -2,23 +2,20 @@ extends Node
@export var human: Human
@export var ray : ShapeCast2D
var interactable : Node2D
var can_interact_with : Node2D
var possible_interactables : Array[Node2D]
func _unhandled_input(event: InputEvent) -> void:
human.stop_interaction()
human.velocityVector = Vector2(0, 0)
human.wants_to_grab = false
human.wants_to_interact_with = null
if (
event.is_action("move_left") or
event.is_action("move_right") or
event.is_action("move_up") or
event.is_action("move_down")
):
human.velocityVector = Input.get_vector("move_left", "move_right", "move_up", "move_down")
human.velocityVector = Input.get_vector("move_left", "move_right", "move_up", "move_down")
if event.is_action_pressed("grab"):
if interactable:
human.wants_to_interact_with = interactable
if can_interact_with:
human.wants_to_interact_with = can_interact_with
else:
human.wants_to_grab = true
@@ -38,10 +35,40 @@ func _process(delta) -> void:
ray.target_position = Vector2(-48, 0)
(ray.shape as RectangleShape2D).size = Vector2(20, 50)
interactable = null
# find all the possible interactables
possible_interactables = []
if ray.is_colliding():
var nbCollisions = ray.get_collision_count()
for n in range(nbCollisions):
var colider = ray.get_collider(n) as Node2D
if colider != null and colider != get_parent():
interactable = colider
if (
colider and colider.get_parent().has_method("start_interaction") and
colider.get_parent().has_method("enable_interaction_clue") and
colider.get_parent().has_method("disable_interaction_clue")
):
possible_interactables.append(colider.get_parent())
# find the closest interactable
var distance_to_closest = Vector2(0, 0)
var closest: Node2D = null
for potential_closest in possible_interactables:
var distance_to_human = abs(potential_closest.global_position - human.global_position)
if distance_to_closest == Vector2(0, 0):
distance_to_closest = distance_to_human
closest = potential_closest
if distance_to_human < distance_to_closest:
closest = potential_closest
distance_to_closest = distance_to_human
# if the new closest is different from the one we had before, notify the one we had before that it shouldn't keep its bubble visible
if can_interact_with != null:
if can_interact_with != closest:
can_interact_with.get_children()
can_interact_with.disable_interaction_clue()
# don't retrigger enabling the clue if it was already enabled
if can_interact_with != closest:
can_interact_with = closest
if can_interact_with:
can_interact_with.enable_interaction_clue()