Godot Version
v4.1.3
Question
I’m working on my first multiplayer project, and I want the player to be able to pick up an object by removing it from the world and then adding it to their inventory. A text hint will show up in the UI to tell the player that this item can be picked up.
With my current code, when the player interacts with the object, it’s obviously only destroyed on their end and not for anyone else. I don’t know how to make it destroy itself for every player.
Also, the label that is supposed to display text when the player is looking at the object displays the default text at all times. When it starts displaying the hinttext, it displays both the hint and the default text at once.
# Interact with Object
func _process(_delta):
if not is_multiplayer_authority(): return
var collider = raycastInteract.get_collider()
if raycastInteract.is_colliding() and collider is Interactable:
if currentCollider != collider:
playingUI.setInteractableText(collider.get_script().getInteractableText())
currentCollider = collider
if Input.is_action_just_pressed("Interact"):
destroyObject(collider)
playingUI.setInteractableText(collider.get_script().getInteractableText())
elif currentCollider:
currentCollider = null
playingUI.setInteractableText("")
else:
playingUI.setInteractableText("")
# Destroy Object
func destroyObject(object):
object.queue_free()
# Display Text
func setInteractableText(text):
if text == "":
interactionLabel.set_text("")
interactionLabel.set_visible(false)
else:
interactionLabel.set_text("Press E to %s" % text)
interactionLabel.set_visible(true)