Having trouble setting individual input control for players in a dedicated server

Godot Version

4.3

Background

In my recent multiplayer journey, I’ve learned how to create a dedicated server, connect clients to that server, and use RPCs in a dedicated server context.

However, when the a second player spawns in, they take control of the first player. This is an issue with client having authority over their own inputs. But I need to have more knowledge in order to fully implement it.

Questions

  1. When I use the property is_multiplayer_authority(), I get confused. Does the dedicated server still have the final say over the client’s actions or does the player have the final say?

The dedicated server must of authority at all times in order to implement networking features needed for a PvP shooter.

Another option for client control would be checking if they have a matching id before every input. Speaking of.

  1. I tried to see each client’s id and name using the print statement. However, when I start the game and join the dedicated server, the prints trigger numerous times and they sometimes don’t match.

Function within _ready() on the player script:

Result with 2 clients:
image

Remote Scene Tree (Same on both sessions):
image

How the player is spawned on the server:

It should only print the client id and name once, but it prints 4 or even 6 times. I’m not sure why that is.

Any help and knowledge will be greatly appreciated.

It spawns both players on both peers, but prints to the same console. Notice the Peer Auth ID is the same twice with 75028… loading in player 75028… and player 14864… Then the peer 14864… loads in both players. If you had three players then each peer would need to load three player objects

2024-10-09-104640_484x270_scrot

1 Like

@gertkeno
That makes sense. That’s natural behavior then.

Now, how do I set a client’s authority via id?

I’ve tried this method, since the player’s name is set when they load on the server.
image


image

Unfortunately, it doesn’t work. As the next client that joins removes the input control of the previous client.

I want to find a way to pass the id or name into the player script via the server script. But I’m not sure how to do that yet.

The name should work, it’s replicated to each player through the MultiplayerSpawner, other values may not be.

How are you calling Jump?

Like this:

I haven’t set _physics_process() or Jump() as an RPC yet because I was handling client input authority first.

Could you expand on what you mean by this? What happens in-game versus what you expect to happen?

I have a feeling it’s just not replicating the movement, if you don’t have position synchronized then I see no reason for jumps to work either.

@gertkeno
What I expect to happen:

  • Client 1 joins and takes control of their player.
  • Client 2 joins and takes control of their player.
  • Etc for all subsequent clients.

What actually happens:

  • Client 1 joins and takes control of their player.
  • Client 2 joins and takes control of their player. But they ALSO completely remove the input control of client 1.
  • If a third client joins, it removes the input control of client 2 and so on.

This issue happens regardless of synchronization method or lack thereof. I think the issue comes from how I set the client input authority and how I pass the id.

So client 1 cannot jump on their own screen?

I’d be very surprised if your set_multiplayer_authority is called again with different values since it’s in _enter_tree, it will only be set once per player as it should.

They cannot move or jump. All input is lost.

I found the issue!

The client does get authority over their player, BUT they don’t get their current camera view.

I need to find a way to make camera.current = true work for all clients.
image

IT WORKED!!!

Here’s the code:

Make sure your player’s camera’s current option is set to false by default.
image

Misc Tips:

  1. When clients first spawn, they must also spawn all concurrent clients. This sounds obvious, but it flew over my head.
  2. For a dedicated server setup, setting the client’s authority only grants access to their own inputs. The server still has the final say in whether the input goes through or not.

Edit: Here’s the solution for the duplicate console printing issue.

Just make sure your checking if the client has authority over their player character before printing.

Result with 2 Clients:
image

Try shortening it by assigning the value directly

CameraRef.current = is_multiplayer_authority()
1 Like

Great idea. It worked like a charm.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.