~kmdodrill/my-brother-lives-in-a-canyon

ref: 80dd997c59c236346ad864508dac4c49b3ad8215 my-brother-lives-in-a-canyon/src/Player/Eyes.gd -rw-r--r-- 1.2 KiB
80dd997c — Kenneth Dodrill Remove misc prints 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
extends RayCast

onready var interact_label: Label = get_parent().get_node("CanvasLayer/CenterContainer/HBoxContainer/Interact")
onready var input_label: Label = get_parent().get_node("CanvasLayer/CenterContainer/HBoxContainer/Input")

var result

func _input(event) -> void:
    if event.is_action_pressed("interact"):
        if !result:
            return
        
        var interactable = result.collider
        if !interactable is Interactable:
            return

        interactable.interact()

func _physics_process(_delta) -> void:
    var space_state = get_world().direct_space_state
    var player_position = global_transform.origin
    
    result = space_state.intersect_ray(player_position, player_position - global_transform.basis.z * 3)
    if !result:
        interact_label.hide()
        input_label.hide()
        return
    
    if result.collider is Interactable:
        if result.collider.active:
            interact_label.show()
            input_label.show()
        return

    interact_label.hide()
    input_label.hide()

func _on_Input_visibility_changed():
    if input_label.visible:
        input_label.text = ": " + InputMapHelper.input_action_events_to_friendly_string("interact")