Godot Version
4.3
Question
I created a game where you have to collect the keys. Everything is fine not until my collected keys reach the max. It just puts the “Press [F] to pick up” visibility on though I check the debugger, there is no collision or whatsoever. and Also, it replaced my "Press [E] to interact cause like what i said, reach the max of the collected items, my interact button, which is supposed to be “E” now got replaced by “F”. I may have overlook the code, but I cant seem to understand where the problem is.
Here’s my code:
extends MeshInstance3D
@onready var pickup_text = get_node('/root/World/UI/pickup_text')
@onready var int_text = get_node('/root/World/UI/interact_text')
var hit_collider = ''
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Emitter.add_listener('not_interacting', Callable(self, 'not_interacting'))
Emitter.add_listener('colliding', Callable(self, 'colliding'))
func not_interacting(_value):
pickup_text.visible = false
int_text.visible = false
Emitter.emit('collider_is_colliding', {'colliding': false, 'key': 'interact'})
func colliding(value):
if str(value).containsn('Key'):
hit_collider = value
int_text.visible = false
pickup_text.visible = true
Emitter.emit('collider_is_colliding', {'colliding': true, 'key': 'pickup'})
func interact():
Collectable.items = Collectable.items.filter(func(item):
return item['Props'] != "Key" or item['value'].name != hit_collider
)
queue_free()
And also my RayCast:
extends RayCast3D
var colliding = false
var key = 'interact'
var int_text # Reference to the interaction UI text
var total_collectables = null
@onready var collectable_text = get_node('/root/' + get_tree().current_scene.name + '/UI/Collectable' )
func _ready():
Emitter.add_listener('collider_is_colliding', Callable(self, 'collider_is_colliding'))
Emitter.add_listener('hide_interact_prompt', Callable(self, 'hide_interact_prompt'))
int_text = get_node('/root/' + get_tree().current_scene.name + '/UI/interact_text')
func collider_is_colliding(value):
if value is Dictionary:
if 'colliding' in value:
colliding = value.colliding
if 'key' in value:
key = value.key
func _process(_delta):
if total_collectables == null:
total_collectables = Collectable.items.size()
if is_colliding():
var hit = get_collider()
if hit:
var collider_parent = hit.get_parent()
if collider_parent:
Emitter.emit('colliding',collider_parent.name)
Emitter.emit('hit_colliding',collider_parent)
else:
Emitter.emit('colliding',hit.name)
Emitter.emit('hit_colliding',hit.name)
var interactable = find_interactable(hit)
if interactable:
var props_name = interactable.get_parent().name
if not colliding:
int_text.visible = true
Emitter.emit('interacting', props_name)
if Input.is_action_just_pressed(key):
interactable.interact()
else:
Emitter.emit('not_interacting', 'none')
int_text.visible = false
else:
Emitter.emit('not_interacting', 'none')
Emitter.emit('not_colliding','none')
int_text.visible = false
if total_collectables:
if (total_collectables - Collectable.items.size()) == 8:
Emitter.emit('complete_keys')
collectable_text.text = 'Keys Collected: ' + str(total_collectables - Collectable.items.size()) + '/' + str(total_collectables)
func find_interactable(node):
while node:
if node.has_method("interact"):
return node
node = node.get_parent()
return null # Explicitly return null if no interactable object is found