Remove_child and add_child in multiplayer

Godot Version



Good afternoon. I’m making a game about flying ships, where one player in online mode can take control of one of the ships, and other players can walk around this ship. Also fight and board other people’s ships. In order for the player to move with the ship, I remove it from the general scene (remove child) and add it to the ship scene. But in multiplayer mode, deleting a player’s scene breaks the synchronization. Godot persistently tries to synchronize with the body at the old address in the scene. Apparently the address is cached. Only complete deletion via queue_free works, but this option is not suitable. Tell me, is there any way to keep the player synchronized by removing him using remove child from the scene root and moving him to the ship using add child?
Or perhaps there is a way to smoothly move the player on the ship and give him the ability to run without removing-adding, so that he moves with the ship even when jumping or while in the air inside it.

Isn’t the ship is just a big moving platform in this case?

Unfortunately no. The ship is a RigidBody3D with a simple collision with which the players do not interact, but the world interacts, and inside it there are StaticBody with which the players interact. Plus, the ship can flood, in which case the players begin to swim and, without touching the floor, RigidBody3D begins to carry them away in motion (in fact, they remain in place relative to the world)

The thing is, if you delete a scene or need to move it in the tree, both the host and client need to do the exact same thing otherwise the syncing authority will be targeting a node in a remote tree that doesn’t exist in the same location as the authority.

The fact of the matter is that simultaneous deletion on the server and client does not produce results. The client continues to try to synchronize with the node at the old location.
It looks like this: Player 2 must get into the submarine. I delete the player node on player 2’s computer and immediately add it to the submarine node. This is immediately done on player 1’s computer. But player 2’s computer still tries to synchronize with the old node, producing errors.

Let’s say when player boards a ship, you do:

player.ship = boarded_ship

in player’s _process or _physics_process, after you calculate player’s velocity, add this line:

if ship:
   velocity += ship.velocity

Or if you can pass ship’s movement vector to player in any other way and just add that vector to player’s movement vector?

I haven’t done networking yet so apologies if this is completely off-base.

if the ship can’t turn, then this will work. But my ship can turn. And the center point of the ship does not correspond to the player’s location.