Godot Model
4.5 Secure
I am attempting to create a multiplayer sport. Since that is my first multiplayer sport I began with a easy LAN setup.
How it’s imagined to work:
When host_button is pressed it calls DBNetwork.init_server() and when join_button is pressed it calls DBNetwork.init_client(). There’s additionally a host_and_join_button which 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: Shopper 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.title = str(id+1)
else:
participant.title = 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 Player 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(title))
func _ready() -> void:
$playerNameLabel.set_text("Participant "+str(title))
Tutorial I’ve Adopted:
https://youtu.be/YnfsyZJRsL8?si=Iu0y4DSzrovEyqaf
Drawback:
Regardless that my code logic is ok (imo) and the tutorial I adopted was adopted appropriately.
The Server Hosts and Shopper Joins efficiently (No Debug Errors) however the participant does not spawn.
How do I repair this?




