Godot Version
4.5
Question
Hello! ![]()
Im trying to make an interactable object in Godot 3D, following a tutorial. I’ve completed everything, including the animation in the animatable body 3D, but when I boot up the game it isnt working. (I have no warnings or errors, either)
I want to make E the way to interact, already set in my input map, and I want the interactable object to disappear and appear in the character’s inventory. I can’t figure out how to do that first part, though :,D
(Node 3D is my interactable area, its parented to the interactable object.)
extends Node3D
@onready var interact_label: Label = $Label
var current_interactions := []
var can_interact := true
func _input(event: InputEvent) -> void:
if event.is_action_pressed("interact") and can_interact:
if current_interactions:
can_interact = false
interact_label.hide()
await current_interactions[0].interact.call()
can_interact = true
func _process(_delta: float) -> void:
if current_interactions and can_interact:
current_interactions.sort_custom(_sort_by_nearest)
if current_interactions[0].is_interactable:
interact_label.text = current_interactions[0].interact_name
else:
interact_label.hide()
func _sort_by_nearest(area1, area2):
var area1_dist = global_position.distance_to(area1.global_position)
var area2_dist = global_position.distance_to(area2.global_position)
return area1_dist < area2_dist
func _on_area_3d_area_entered(area: Area3D) -> void:
current_interactions.push_back(area)
func _on_area_3d_area_exited(area: Area3D) -> void:
current_interactions.erase(area)
This is the code for the animatablebody3d, which is a parent of the node3d
extends AnimatableBody3D
@onready var interactable: Area3D = $"Interactable Instance"
func _ready() -> void:
interactable.interact = _on_interact
func _on_interact():
if $AnimatableBody3D.frame == 0:
$AnimatableBody3D.frame = 1
interactable.is_interactable = false
print("Memory")