Search Unity

Third Party Using Photon View To Sync WheelCollider how?

Discussion in 'Multiplayer' started by DRIVER1ksa, Jan 22, 2017.

  1. DRIVER1ksa

    DRIVER1ksa

    Joined:
    May 29, 2015
    Posts:
    28
    I'm Making a multiplayer game using photon

    everything is working fine except that other players don't see the Wheel Colliders "suspension distance" updating

    Ive added a photon view component to the Wheel Colliders, and observe but doesn't work



    not sure how wheel wheelcolliders will sync across the network
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    When the PhotonView is set to observe the RCC Wheel Collider script, that should implement OnPhotonSerializeView(). The trick is to write the values that are needed to replicate the behaviour on the remote player's clients (which read the incoming values).
    Also, for remote-controlled vehicles, you must somehow deactivate the physics system or it will try to control someone else's vehicle locally.

    Note: When working with complex physical objects, it's often tricky to make things work when there's network loss and (more or less) random lag. Any delay for networked objects is in contrast with locally controlled, physical objects.
    We don't have a silver bullet to fix this without extra effort, so hopefully you find a solution that works well for your game.
     
  3. Maverickjw

    Maverickjw

    Joined:
    Oct 21, 2020
    Posts:
    6
    I got a similar problem with suspension. Im working in a 2D race game and it has a lot of jumps, so suspension is very important for visuals. Im using WheelJoint2D (car and both wheels have each a rigidbody attached) and using PhotonRigidbody2D View and works ok for car movement, but not much for suspension, tires go crazy when doing a jump, even worst if they make a loop.

    As a solution, for the client, i disabled the WheelJoints and destroyed the Wheel rigidbodies(tried first to set them on kinematic but the car is like floating and moving funny), also added OnPhotonSerializeView to manually replicate the rotation of wheels. The result was that the Car moved ok, wheels worked fine, but still not getting the suspension seen as a local player.

    As an added solution, in the OnPhotonSerializeView added the wheels Y axis local position. The result is that replicating the suspension now works but with a little delay in big jumps and not very smooth as you can see in the local player. Also added a little Lerp, but doesnt make much difference.

    So im running out of ideas to replicate the suspension a wheeljoint2d gives, and came here for some help.
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Part of the problem will be that PUN does not perfectly sync the path an object moved on the client which controls it. So when others receive the updates with varying delay (rtt variance), the car does not perfectly align with the ground. Also, it gets sped up or slowed down to make up for delays or imprecision.
    So cars may sink into the ground or float above it and this of course messes with the local physics, if it's enabled.

    If this needs perfect replication, I would suggest using Quantum. It controls the complete (deterministic) simulation and aside from some corrections, it is the closest you'd get to a perfect result. Best of all: You don't have to worry about the networking as Quantum only transfers input anyways and everything else is (or rather has to be) deterministic.

    Fusion would also be a better solution than PUN, as it provides tick based networking precision and is generally really good at replicating movement. It also runs physics on the server/host and updates everyone else, so collisions become more feasible. Unless you consider the project done, I'd look into this.

    With PUN 2, I can't really help all that much. It is sometimes rather hard to hide the lag and imprecise timing.
    You should likely disable the physics of the "proxy" versions of cars or run a simplified model which provides good visuals (while not being useful to actually drive the car).

    It might make sense to look into the Smooth Sync package in the Asset Store. It supports PUN 2 and adds components which should help you improve the synchronization.
     
  5. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    From the Fusion discord channel, they said that Wheel Colliders cannot be used in Photon Fusion because they can't simulate the ticks properly. I don't think there is a way to achieve networked wheel colliders in there. I've been searching for a script or something for a while already.