Godot model
4.5 Steady
I am attempting to create a multiplayer recreation. Since that is my first multiplayer recreation, I began with a easy LAN setup.
The way it’s purported to work:
When host_button flame is pressed DBNetwork.init_server() and when join_button flame is pressed DBNetwork.init_client(). There’s additionally a host_and_join_button It tries to host the server and spawn in a participant. This triggers the host_player_exists variable.
Code:
DBNetwork.gd:
extends Node
var network_peer : ENetMultiplayerPeer
var DEFAULT_PORT : int = 43500
var LOCAL_IP : String = "localhost"
var MAX_CLIENTS : int = 10
func init_server() -> void:
network_peer = ENetMultiplayerPeer.new()
network_peer.create_server(DEFAULT_PORT, MAX_CLIENTS)
multiplayer.multiplayer_peer = network_peer
print("DBNetwork: Server Hosted Efficiently")
func init_client() -> void:
network_peer = ENetMultiplayerPeer.new()
network_peer.create_client(LOCAL_IP, DEFAULT_PORT)
multiplayer.multiplayer_peer = network_peer
print("DBNetwork: Consumer Created Efficiently")
MultiplayerSpawner.gd:
extends MultiplayerSpawner
@export var player_scene : String
@export var host_player_exists : bool = false
func _ready() -> void:
multiplayer.peer_connected.join(spawn_player)
func spawn_player(id: int) -> void:
if !multiplayer.is_server():
return
var participant : CharacterBody3D = load(player_scene).instantiate()
if host_player_exists:
participant.identify = str(id+1)
else:
participant.identify = str(id)
get_node(spawn_path).call_deferred("add_child", participant)
func _on_host_and_join_button_pressed() -> void:
if !host_player_exists:
spawn_player(1)
host_player_exists = true
else:
print("DystopianBots: Failed To Spawn Participant! (Host Participant Already Exists)")
Participant.gd:
extends CharacterBody3D
@export var SPEED : float = 100.0
@export var camera_sensv : float = 1.0
func _enter_tree() -> void:
set_multiplayer_authority(int(identify))
func _ready() -> void:
$playerNameLabel.set_text("Participant "+str(identify))
Tutorial I adopted:
https://youtu.be/YnfsyZJRsL8?si=Iu0y4DSzrovEyqaf
Drawback:
Though the logic of my code is okay (in my view) and the tutorial I adopted was adopted accurately. The server hosts and the shopper joins efficiently (no debug errors), however the participant doesn’t seem.
How do I repair this?

