- Edited
OS: Linux Mint 21.3 x86_64
Godot version: 4.4.stable
I'm trying to make a multiplayer test project with ENet multiplayer, just to get the hang of it. But no matter how I try, my code doesn't seem to work. I was following this tutorial by 16BitDev:
I tried exporting the project for windows 11 on another computer and it worked perfectly fine, but when i export the project for linux and do the same thing to test as I did on windows 11, it just didn't work. I used the same testing method on both OSs as in the tutorial I mentioned earlier. I also tried doing the same thing as 16BitDev did in the video (without exporting the project), but it still wouldn't work. I tried asking chatGPT for help, but it's code didn't help. Here is my code if it helps:
#main.gd
extends Node2D
var peer = ENetMultiplayerPeer.new()
@export var player_scene: PackedScene
func on_host_pressed() -> void:
peer.create_server(631)
multiplayer.multiplayer_peer = peer
multiplayer.peer_connected.connect(add_player)
_add_player()
func _on_join_pressed() -> void:
peer.create_client("localhost", 631)
multiplayer.multiplayer_peer = peer
func _add_player(id = 1):
var player = player_scene.instantiate()
player.name = str(id)
call_deferred("add_child", player)
,
#player.gd
extends CharacterBody2D
var speed : int = 10000
var slow_speed : int = 200
func _enter_tree() -> void:
set_multiplayer_authority(name.to_int())
func _physics_process(delta: float) -> void:
var move = Input.get_vector("left", "right", "forward", "back")
if is_multiplayer_authority():
velocity = Input.get_vector("left", "right", "forward", "back") * move * speed * delta
velocity = velocity.clamp((Vector2.ONE * -1200), (Vector2.ONE * 1200))
if move == Vector2.ZERO:
velocity = velocity.move_toward(Vector2.ZERO, delta * slow_speed)
move_and_slide()
Maybe I'm just dumb and the "issue" isn't real but I've been trying to get peer-to-peer multiplayer working for a little while now and I will appreciate any help whatsoever