Godot Version
4.2
Question
Hey, I’m new so I’m really not sure of the quality of my code and I need some help syncing item pickups on all peers. So, the game is P2P and my method of syncing item pickups right now is to use a multiplayer spawner. I’m not sure how to RPC my pickups (if necessary) and I haven’t even started on dropping items, so if anybody could offer a bit of help when it comes to implementing this, I would really appreciate it.
(called in _unhandled_input)
if not is_multiplayer_authority():
return
if event is InputEventKey:
if Input.is_action_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_pressed("interact"):
var looking_at = ray.get_collider()
if looking_at != null:
if looking_at.is_in_group("interactable"):
if looking_at.is_in_group("hoverable"):
looking_at.hover()
if looking_at.is_in_group("usable"):
if looking_at.is_in_group("harpoongun"):
if !armed:
armed = true
gun.show()
if looking_at.is_in_group("holdable"):
if !holding:
pickup(looking_at.type)
else:
looking_at.interact.rpc(name)
if Input.is_action_just_pressed("drop"):
if holding:
pass
code for the pickup itself:
func pickup(interactable):
var held_object = interactable.instantiate()
hold_root.add_child(held_object)
held_object.held = true
holding = true
BTW, looking_at.type is an exported variable that stores the packed scene of the item I want to pick up. If there’s a better way to do this PLEASE let me know!
Right now, on the hosts end, it gives joined players the item when they pick it up (I don’t yet free the picked up item), but when the host picks it up the players can’t see it.
Anyways, I would really appreciate any help offered regarding this and anything else that you would tell me to change. i.e maybe I should use class types instead of groups for selection.