Client lagging behind spaceship

I have a setup where I have a Spaceship object, with a PlayerGroup and ShipObject parented under it. The PlayerGroup is the parent of players inside that Spaceship and ShipObject has a movement script for the ship on it. The ShipObject also has the following script attached:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayersFollowShip : MonoBehaviour
{
    [SerializeField] private GameObject playerGroup;

    void Start()
    {
        var spaceshipObject = transform.root.gameObject;
        playerGroup = spaceshipObject.GetComponent<Spaceship>().playerGroup.gameObject;
    }

    void Update()
    {
        playerGroup.transform.position = transform.position;
        playerGroup.transform.eulerAngles = transform.eulerAngles;
    }
}

When the host is in the ship and parented under the player group, when the ship is moved with the movement script, the host’s player object stays in place correctly inside the spaceship, but when I do the same with a client it always physically lags behind the ship. Any ideas on how to fix this and make sure the client player object correctly stays inside the spaceship and doesn’t lag behind it?

You might take a look at this modified version of the bite size samples client driven example where it shows how to parent objects with an owner authoritative motion model onto a platform that is driven by the server (or could be modified to be driven by a client) without the issue you are experiencing.

You can see the modifications here.

Where the CustomClientNetworkTransform includes additional code to handle the unique parenting (i.e. not using the standard NetworkObject parenting, but rather using a NetworkVariable to synchronize if a player is parented under the moving platform).

Also look over the PlatformMover script, as that uses the PlatformVisualMover to keep the visual and physics/collider portion of the platform in synch on each client side.

The basic gist is when a player is parented it will move in local space relative to the parent (platform or in your case space ship) and when exited it reverts back to world space motion. The “visual portion” of the platform handles motion client relative to assure the latency between the clients and server are taken into account.