godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.09k stars 21.18k forks source link

MultiplayerSynchronizer and players sharing collider layer causes undesirable spawn location #91005

Open LexGear opened 6 months ago

LexGear commented 6 months ago

Tested versions

Reproduced in Godot 4.2.1

System information

Windows 11 - Godot 4.2.1

Issue description

When setting up a simple local network fps game, I discovered that if players share the same collider layer, regardless of where the first player is currently when the second player joins, the new player will appear in either a seemingly random location or on top of the last-player-to-join's head.

I believe this is due to the very first frame on the joining clients end where both players occupy the same 0, 0, 0 location before the MultiplayerSynchronizer has had a chance to position the players retrospectively.

Steps to reproduce

Create a simple network capible game using a MultiplayerSpawner node, a simple flat plane, and a player scene containing:

Minimal reproduction project (MRP)

You can use https://github.com/devloglogan/MultiplayerFPSTutorial project as an example, but you need to set the player collider layer to 1 so that every player shares the same collider layer.

sleepyghostdev commented 5 months ago

Are there any good work arounds for this?

LexGear commented 5 months ago

Are there any good work arounds for this?

In my case, what I did was to simply remove collisions with players. This worked out okay for me because I replaced it with a little bit of code to give the players a soft push away from each other instead of it being rigid.

Jay-ArBrouillard commented 4 months ago

@LexGear Can you share any code on your work around? I have the same issue with my project. Turning off the collision mask on my player "fixes" as you mentioned but now I don't have collisions between players.

tspring5000 commented 1 month ago

@LexGear Can you share any code on your work around? I have the same issue with my project. Turning off the collision mask on my player "fixes" as you mentioned but now I don't have collisions between players.

Not sure why, but it seems the problem only occurs when spawning at (0,0) (or presumably 0,0,0 for 3D). Setting the position to anything else during _enter_tree() seems to fix it with collisions enabled

EDIT: I do still get some problems when the x axis is 0 (y axis seems to behave fine whether its 0 or not), but only sometimes, so I'm not certain on that and I could be missing something. For safety, I just set the position to something like (-1,-1)

LexGear commented 1 month ago

@LexGear Can you share any code on your work around? I have the same issue with my project. Turning off the collision mask on my player "fixes" as you mentioned but now I don't have collisions between players.

Not sure why, but it seems the problem only occurs when spawning at (0,0) (or presumably 0,0,0 for 3D). Setting the position to anything else during _enter_tree() seems to fix it with collisions enabled

EDIT: I do still get some problems when the x axis is 0 (y axis seems to behave fine whether its 0 or not), but only sometimes, so I'm not certain on that and I could be missing something. For safety, I just set the position to something like (-1,-1)

Sometimes it feels a bit random, yeah?

tspring5000 commented 1 month ago

@LexGear Can you share any code on your work around? I have the same issue with my project. Turning off the collision mask on my player "fixes" as you mentioned but now I don't have collisions between players.

Not sure why, but it seems the problem only occurs when spawning at (0,0) (or presumably 0,0,0 for 3D). Setting the position to anything else during _enter_tree() seems to fix it with collisions enabled EDIT: I do still get some problems when the x axis is 0 (y axis seems to behave fine whether its 0 or not), but only sometimes, so I'm not certain on that and I could be missing something. For safety, I just set the position to something like (-1,-1)

Sometimes it feels a bit random, yeah?

It looks like I'm not having too any problems anymore, though to be fair you do also need to sync position for this to work. Unfortunately, it seems to happen just after spawn, so MultiplayerSynchronizer needs to sync it permanently. There's probably a fix for that using RPC's, I tried for a while but for now I'm just syncing position