Search Unity

Scene Prop Syncing?

Discussion in 'Multiplayer' started by Jick87, Jul 13, 2017.

  1. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    Using UNET, what would be the best approach to keep many (hundreds of) physics scene objects synced across the network (position/rotation/etc)?

    They are items built into the scene (not spawned) that have rigidbodies and colliders. Players should be able to push them around and such with physics. The players are also physics-based (i.e. not Character Controller).

    That works fine with one person in a single instance, but syncing that across the network seems tricky. No one single player owns the objects, they are simply props in the scene that can be moved around by anyone via pushing them by running up against them, not by picking them up or such (i.e. assigning authority isn't viable).

    I guess a good example might be Gmod Prop Hunt. Players can move the props anywhere by simply bumping into them. Again, that is easy in a single player context, not so much in multiplayer it seems.

    Just using the built-in Network Transform doesn't seem to work very well. I've tried tweaking the settings there in every way I could think of, but it just doesn't want to work very well it seems.

    Thanks!
     
  2. Deleted User

    Deleted User

    Guest

    Are you looking for something like that? (skip to 00:18)

     
  3. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    Yes, that looks really nice! Do you know how it is achieved in that video?

    Thanks!
     
  4. Deleted User

    Deleted User

    Guest

    Yeah, it's my video actually) Basically what I have done it's calculated all physics on server side and then simply sent position and rotation of an object to client and applied it with interpolation with kinematic rigidbody.
     
  5. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    I don't suppose you have any code you'd be willing to share? Even just a stripped-down version that covers the basic parts. I've been searching all over the place and tried many things found on Google, but nothing seems work as well as it seems to in that video. I've even tried coding myself with the same concept you outline, but it never seemed to work for me. But maybe I got something wrong when I tried.

    Thanks!
     
  6. Deleted User

    Deleted User

    Guest

    Chech my blog:
    https://wobesdev.wordpress.com/2016/09/09/networking-on-unity5/

    That one is for player object, in order to make it works for non player object, simply remove commands and change the syncvar only on server so the object would automatically synchronized and interpolated on client.
     
  7. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    Thanks for that! I think it is kinda working...

    The only issue is related to my player. My player is currently Local Player Authoritative, so it's pretty much like the unmodified script on your site. However I can't seem to make any props move around by running into them. When I run into them they are completely immovable, as if they were static geometry.

    I'm guessing maybe it is due to the fact that players (that are not the local player) have their instances of that player set to kinematic, so no forces are automatically applied. And the server runs the physics for the props. So what you have ultimately on the server is kinematic players (who are just having their position/rotation updated and not any forces) bumping into non-kinematic props that the server owns. So I guess that kinda makes it a one-way physics setup that way. I guess what is needed is for both to be non-kinematic at the same time on the server, but that doesn't seem possible.

    Do you know how I might go about fixing that?

    A real (seemingly)hacky idea I thought of is to check for collisions from kinematic players and manually add some force (with AddForce() or similar). That seems like not a very good idea though, and might not even work?

    Or maybe I'm missing something obvious? :p

    Thanks so much for your help!
     
    Deleted User likes this.