(Godot 3.5 3D) i'm making a interaction system and i have a problem with the "Area" node


Godot 3.5 (GDScript)


I’m making an interaction system (for example: open doors, disappear objects, etc.) and I want to make as if the character was doing those actions with his hands and for that I’m using an “Area” node to get the object’s methods and so I can do the desired actions, and I’ve found that I don’t know how to use correctly the “Area” node XD.

here is the code:

extends Node

onready var interact_label = $"../UI_Debug/E"

onready var _input_node = $"../input_save_node"

func _on_Hands_area_body_entered(body: Node) -> void:
	if body.has_method("interact"):
		interact_label.visible = true
		if _input_node.interact_action:
		interact_label.visible = false
	print("a, ", body)

I realized that the mistake I am making is that I am using the _on_Hands_area_body_entered(body: Node) signal as if it were a _process(delta) and I also realized that I can’t call the function or assign the variable body to another one, and I wanted to know if there was any other way to make the interactions as if the character was using his hands.

I´d like to know a bit more about this. Just explain the process with more details

thank you very much, but I already solved it.

But the idea was that when the Area node collides with a body that has the interact() method, it makes appear a Label node that indicates that you can interact with that object showing an E, and if you press the interaction key (in this case “E” or right click), that function is called inside that object, and that function removes that object from the scene.

what I had to do was not as crazy as I had thought at the time, i just save the body data from the _on_Hands_area_body_entered(body) signal in a separate variable, that is:

# rest of the code that is not so relevant

var entered_object : Node

func _process(delta: float) -> void:
	if !entered_object == null:
		if entered_object.has_method("interact"): interact_label.visible = true
			if Input.is_action_just_pressed("Interact"): entered_object.interact()
		if entered_object.has_method("open_and_close_door"): interact_label.visible = true
			if Input.is_action_just_pressed("Interact"): entered_object.open_and_close_door()
		else: interact_label.visible = false
func _on_Hands_area_body_entered(body: Node) -> void: 
    entered_object = body

func _on_Hands_area_body_exited(body: Node) -> void: 
    entered_object = null