0

Currently, I am using High Level Multiplayer (ENET) with Godot to spawn two player nodes (with KinematicBody2D and Collisions). For reasons of collisions causing problems, I cannot have the players spawn in the same coordinates, so I am trying to get them to spawn next to each other.

I put my Player.gd on this pastebin link which has the code I am trying to debug.

The problem I am having is trying to get the client and server to spawn the players at the coordinates I have set in the initialization of the player scene. Currently, the client and server can position themselves correctly, but the other player hangs out at (0,0) until I move the player.

The player movement works perfectly, so even though that code is in the paste, it isn't relevant to this question.

The client's stdout is

Connecting to Server!!!
Player Connected!!!
Network Master: 151057035
Player ID: 151057035
Client Position - Master: 151057035
Player: 151057035 Set Position: (500, 250)
Own ID: 151057035 Player ID: 151057035
Caller ID: 0
Network Master: 1
Player ID: 151057035
Server Position - Master: 1
Player: 1 Set Position: (300, 250)
Player: 1 Set Position: (300, 250)
Player: 151057035 Set Position: (500, 250)
Own ID: 151057035 Player ID: 151057035
Caller ID: 1

The server's stdout is

Hosting Server!!!
Player Connected!!!
Network Master: 1
Player ID: 1
Server Position - Master: 1
Player: 1 Set Position: (300, 250)
Own ID: 1 Player ID: 1
Caller ID: 0
Network Master: 959488417
Player ID: 1
Client Position - Master: 959488417
Player: 959488417 Set Position: (500, 250)
Player: 959488417 Set Position: (500, 250)
Player: 1 Set Position: (300, 250)
Own ID: 1 Player ID: 1
Caller ID: 959488417
Alexis Evelyn
  • 304
  • 5
  • 17
  • I found out about (https://github.com/Kehom/gdMultiplayerTutorial) from https://www.reddit.com/r/godot/comments/bpxmq4/tutorial_how_to_setup_multiplayer_game/. Running this project shows that the two players are spawned separately and can move properly. I am going to study the code and follow the tutorial and then come back to this question with the answer to solve my problem. I am probably also going to scrap my whole project (pasted above) as the project is only meant to teach me how to implement multiplayer (as in it's not a real game). This Github project does everything I want and more. – Alexis Evelyn Jul 20 '19 at 00:26
  • It turns out that setting up the clients properly is very complicated and very specific to the game. I have managed to setup my code to work perfectly with two players, but it bugs out when I add a third player. The 2nd player starts to bug out as the the third player does not register properly (even though the server and 2nd player registers to the list of players just fine). I will not be able to write an answer to this question until I solve the bug and given that it is implementation specific, a StackOverflow answer may not be of any use. – Alexis Evelyn Jul 25 '19 at 19:36
  • I fixed the bug that I introduced (while fixing a security hole). I am going to answer the question later when I figure out how best to explain networking. The coordinates in my code as sent by the server (and can be loaded from save). Anyone who needs an answer sooner can check out my commit where I fixed the bug: https://github.com/SenorContento/Sweet-Tea/commit/845fded192772a3977b143acd8b57ce5a8eeb690 – Alexis Evelyn Jul 25 '19 at 20:52

1 Answers1

0

Basically, to tell the client what coordinates to spawn at, you need to have the server tell the client what coordinates to use.

My own personal code involves player registration and tracking, so it is too complicated to just paste the full code. Instead, I am posting a greatly simplified spawn code (that does not even include multi-world support)


Sample Code

# Server Code
master func spawn_server(net_id: int, coordinates: Vector2):
    rpc_unreliable_id(net_id, "spawn", coordinates) # Godot's RPC handles ensuring packet delivery just like TCP, but with less overhead.

# Client Code in Same File
puppet func spawn(coordinates: Vector2):
    player_object.position = coordinates
Alexis Evelyn
  • 304
  • 5
  • 17