Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Networked Two-Part Object Question

Discussion in 'Multiplayer' started by marty, Aug 1, 2008.

  1. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    I'm working on a networked "tank" which consists of a tank body (rigidbody) with a gun-tower child object. I've got the tank moving across the network, but the turret is giving me grief.

    Here's some detailed info ...

    At the root of the tank object, I have a rigid body and collider. There, I've attached a NetworkView and the Unity Networking Demo's NetworkRigidBody script. This works fine for moving the tank across the network.

    My problem is that I'm not sure how to approach moving the tank's turret. I've attached a separate NetworkView to the turret object (a child of the tank root), along with the Network Demo's NetworkInterpolatedTransform script. Unfortunately, while the turret moves across the network, it does so with a jerkiness. It looks like it is moving to match networked movement, then fighting to get back to the default position on the client.

    Anyone have any thoughts/experience to share on how to best set up something like this?

    TIA!
     
  2. jeffcraighead

    jeffcraighead

    Joined:
    Nov 15, 2006
    Posts:
    740
    I've been using this same approach for various parts of a robot with success, there is still some, but minimal stuttering. You need to make sure the Lerp that is called from NetworkInterpolatedTransform is happening correctly (and in the amount of time you want) and prevent the turret from trying to move back to a default (why does it do that? it should stay where you left it last).
     
  3. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    It only stutters, and presumably tries to return to it's non-rotated position, on the other players' computers.
     
  4. Orion

    Orion

    Joined:
    Mar 31, 2008
    Posts:
    257
    I think you shouldn't update the position of the turret at all and have it part of the object on client computers. Then you just update the rotation of the turret on the vertical axis. Because obviously the posiiton of the turret is ALWAYS on top of the tank, this data doesn't nee sending.

    You do this by "observing" a script with the NetworkView as described here:
    file://localhost/Applications/Unity/Unity.app/Contents/Documentation/Documentation/Components/class-NetworkView.html

    There you would just serialize the rotation of the turret.
     
  5. SixTimesNothing

    SixTimesNothing

    Joined:
    Dec 26, 2007
    Posts:
    167
    you shouldn't be using 2 NetworkViews, it will only increase your network load. use the one for the tank to serialise everything, and like Orion said, you don't need to sync properties that never change like the position of the turret.

    i actually have networked tanks with moving turrets and sponsons in the game i'm working on. i'll share my code when i get home tonight.