Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi Ropes Multiplayer Sync
#1
Hello,
Im trying to sync the rope between client and server but its still kind of weird.
The rope is not getting tense on either the client or the server and the players cant drag the other player properly. ( before multiplayer they could)
Here is some footage: Video

and this is how im syncing the Rope:
Code
Reply
#2
(27-09-2023, 04:25 PM)fevzi Wrote: Hello,
Im trying to sync the rope between client and server but its still kind of weird.
The rope is not getting tense on either the client or the server and the players cant drag the other player properly.

Getting/setting particle properties in FixedUpdate() will not work, since the order in which Unity calls FixedUpdate for different objects is undefined. The solver might be updated before or after you get/set the data, leading to inconsistent results.

Use one of the solver callbacks to make sure to always get/set particle data at the same point in time. ObiSolver. OnEndStep is the preferred way to do this, as it is called whenever the solver has finished a physics step.

kind regards,
Reply
#3
(27-09-2023, 06:01 PM)josemendez Wrote: Getting/setting particle properties in FixedUpdate() will not work, since the order in which Unity calls FixedUpdate for different objects is undefined. The solver might be updated before or after you get/set the data, leading to inconsistent results.

Use one of the solver callbacks to make sure to always get/set particle data at the same point in time. ObiSolver. OnEndStep is the preferred way to do this, as it is called whenever the solver has finished a physics step.

kind regards,
moved all to the EndStep function but tension still not syncing Code
Reply
#4
(27-09-2023, 08:59 PM)fevzi Wrote: moved all to the EndStep function but tension still not syncing Code

There's lots of issues with your code:

- I don't know which networking system are you using, but this code:

Code:
public void OnEnable()
    {
        if (IsClient)
        {
            GetComponent<ObiActor>().OnEndStep += EndStep;
        }
    }

Looks as if only the client subscribes to OnEndStep. In OnEndStep you're checking whether the subscriber "IsServer" before sending data, but since only clients subscribe, no data will ever be sent. Might be the case that the server is also a client, but you should definitely look into this just in case.

- You're synchronizing invRotationalMasses: which is only used by oriented particles in rods. It is unused by ropes.
- You're synchronizing invMasses, these values don't change at runtime (unless you explicitly change them) so no need to synchronize them.
- You're synchronizing externalForces and externalTorques, which as the name implies they're used to inject external forces/torques into the simulation and will be zero unless you explicitly set their values. No need to synchronize.

- You're not synchronizing startPositions and prevPositions, which are used to interpolate physics state, so state interpolation will break.
- You're not synchronizing velocities (may or may not be needed for your specific use case).
- You're using rope.GetParticleRuntimeIndex(i), which returns the index of the particle either in the actor or the solver. This is intended to be used when writing editor tools only, at runtime you should use rope.solverIndices instead.

I'd suggest taking a look at the scripting section of the manual for details.
Reply
#5
(28-09-2023, 08:24 AM)josemendez Wrote: - You're not synchronizing startPositions and prevPositions, which are used to interpolate physics state, so state interpolation will break.
Sorry, i dont want to bother you, but im new to programming and all of this is a little hard for me to understand. Could you maybe tell me how to sync start and prev positions ?
Reply
#6
(28-09-2023, 09:28 AM)fevzi Wrote: Sorry, i dont want to bother you, but im new to programming and all of this is a little hard for me to understand.

If you're new to programming, starting with something as complex as deformable physics synchronization over the network is probably a very bad idea. There's tons of concepts that you'll need to understand to get this to work, otherwise you will probably get stuck every step of the way.

(28-09-2023, 09:28 AM)fevzi Wrote: Could you maybe tell me how to sync start and prev positions ?

Same as you're doing with the other arrays, but using rope.solver.startPositions and rope.solver.prevPositions.

cheers,
Reply
#7
(28-09-2023, 09:34 AM)josemendez Wrote: If you're new to programming, starting with something as complex as deformable physics synchronization over the network is probably a very bad idea. There's tons of concepts that you'll need to understand to get this to work, otherwise you will probably get stuck every step of the way.


Same as you're doing with the other arrays, but using rope.solver.startPositions and rope.solver.prevPositions.

cheers,
I have managed to sync the rope. Only Problem is, when setting the invMass to 0 for the client, the client cant move anymore. 

Video
Code
Reply