Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi rope with Photon Fusion 2 disconnects from attachment
#1
I need to spawn objects in runtime, so everything needs to be a prefab. When creating a scene, I instantiate obi rope and spawn 2 plugs, that I can pick up, I connect them to the rope and that is it. On host: Everything works fine, on client: rope gets disconnected from plug and starts to do some weird movement. That only happens when everything is instantiated in runtime.
SimulationBehaviour code:
Code:
bool first = true;
public void OnPlayerJoined(NetworkRunner runner, PlayerRef player)
{
    if (runner.IsSceneAuthority)
    {
        if (first)
        {
            runner.Spawn(prefab, new Vector3(1, 0.089f, 0));
            runner.Spawn(prefab, new Vector3(-1, 0.089f, 0));
            first = false;
        }
        runner.SetPlayerObject(player, runner.Spawn(playerPrefab, new Vector3(UnityEngine.Random.Range(-10, 10), 1, UnityEngine.Random.Range(-10, 10)), inputAuthority: player));
    }
}
plug code (there is more code, but for this question, this is the important part. Parent is in main project something else, this is just for testing):
Code:
Transform parent;
Rigidbody rb;
private void Start()
{
    parent = transform;
    rb = parent.GetComponent<Rigidbody>();
    if (a.Att1.target == null)
    {
        a.Att1.target = transform;
    }
    else
    {
        a.Att2.target = transform;
    }
}
public void Pickup(Transform hand)
{
    rb.isKinematic = true;
    rb.useGravity = false;
    parent.SetParent(hand);
    parent.localPosition = Vector3.forward;
}
public void Release()
{
    rb.isKinematic = false;
    rb.useGravity = true;
    parent.SetParent(null);
}
I also set the Time.timeScale = 0 at start of creating the scene, and at the end back to 1.
Here is a video for better understanding of the problem: [color=var(--theme-link-color-hover, var(--theme-secondary-500))]https://drive.google.com/file/d/1P0H2jcFyjb4VeKeQxLUOMf9-ppuZqm9X/view?usp=sharing[/color]
Reply
#2
Hi Paul,

The code you shared doesn't seem related to this behavior. If I had to guess, I'd say there's some issue with the mass ratios of the rigidbody and the rope particles (since making the attached rigidbody kinematic fixes the issue, by making its mass infinite) but it's difficult to tell for sure just from the video.

Would it be possible for you to share the project by sending it to support(at)virtualmethodstudio.com so that i can take a closer look? thanks!
Reply
#3
Hi Paul,

The problem is that ropes are not synchronized between server and client at all, and neither are rigidbody velocities. As a result, any velocity-dependent effects such as joints, friction, or in Obi's case dynamic attachments won't work properly.

In this case the client's rope is applying a force to the rigidbody which modifies its velocity. It stands to reason that the server would then set the client's rigidbody velocity to zero (as the rigidbody isn't moving in the server), but that's not the case: only the position is synchronized, which is akin to teleporting the rigidbody back to the position dictated by the server. The client's velocity value is kept and as a result the rope starts wandering around as it believes the rigidbody is about to move to a new location - after all the server is not telling it otherwise!

A simple workaround is switching the client's attachments to static instead of dynamic. Since static attachments work purely based on position and do not involve forces/accelerations/velocities, the lack of velocity syncing doesn't have any negative effects.

A proper solution would involve syncing either rigidbody velocities, or syncing particle positions - so that the client's rope particles are properly sync'ed.

kind regards,
Reply
#4
Hi,

yes, that worked! Thank you very much. I set it to static on client and it works. About syncing rigidbody, I have NetworkRigidbody component on both plugs, so that should be fine? Maybe it has something to do with timing of obi and Fusion. I don't know, I'm not an expert at this area.

Best regards
Reply
#5
(09-10-2024, 01:56 PM)Paul1 Wrote: bout syncing rigidbody, I have NetworkRigidbody component on both plugs, so that should be fine?

Hi!

NetworkRigidbody only seems to sync rigidbody position/orientation. I don't have any experience with Fusion, but looking at their code it just seems to do that.

For proper syncing you will also need linear/angular velocities, my advice would be to ask them about this. There must be a way for velocities to be synced as well, otherwise lots of rigidbody-related behavior will be broken.

(09-10-2024, 01:56 PM)Paul1 Wrote: Maybe it has something to do with timing of obi and Fusion. I don't know, I'm not an expert at this area.

Timing doesn't play any role here, it's just that data is missing on the client.

kind regards,
Reply