Skip to content

CharacterBody2D position inconsistent across clients depending on collision layer mask #100993

Open
@RyanRemer

Description

@RyanRemer

Tested versions

  • Reproducible in v4.3.stable.official [77dcf97]

System information

Windows 11 - v4.3.stable.official [77dcf97] - Forward+ - NVIDIA GeForce RTX 4070 Laptop GPU

Issue description

I ran into an interesting bug with the CharacterBody2D physics and Networking. My simple example spawns the "Host" at 500,500 and the "Client" at 0,0. But then the client moves to 500,480 within a few frames.

Example 1: Players have default collision layers

"Host" window has the "Client" player at 0,0 (as expected) but the "Client" window moves the player from 0,0 to 500,480.

Image

Logged position changes:

Changed position (0, 0) (500, 500)
Changed position (0, 0) (0, -17.47415)
Changed position (0, -17.47415) (500, 480.2612)
Changed position (500, 480.2612) (500, 479.9677)

Example 2: Players ignore other players

If the collision layer is changed to "2" (i.e. the players don't collide with each other) then the position of the "Client" is consistent.

Image

It also is "fixed" by commenting out "move_and_slide();" on line 27 of "player.gd"

Thankfully, for my game I don't want the players to collide, so it it is good enough for me, but I would expect the "Client" player to be at 0,0 without changing the layer since the other player object is nowhere near (500,500).

Steps to reproduce

  1. Get the code from the attached project or clone the commit from my repro https://github.com/RyanRemer/multiplayer_1227/tree/ddef2c3baa4fc9119e5ce523030129106e95e9db
  2. Run 2 instances of the game
  3. Click "Host" on one and "Join" on the other
  4. The "Client" player is at different positions on each window. On the "Host" they are at 0,0 but on the "Client" they are at 500, 479.9677.

Here is the log of any position changes:

Changed position (0, 0) (500, 500)
Changed position (0, 0) (0, -17.47415)
Changed position (0, -17.47415) (500, 480.2612)
Changed position (500, 480.2612) (500, 479.9677)

To "fix" it, change the Player > Collision > Layer to "2" instead of "1"
RyanRemer/multiplayer_1227@d71a7cd
Of course, this has the side effect that players don't collide with each other

Minimal reproduction project (MRP)

https://github.com/RyanRemer/multiplayer_1227/tree/ddef2c3baa4fc9119e5ce523030129106e95e9db

I also removed some other files to try and minimize the project here.
project.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions