Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Synching rigidbodies

Discussion in 'Multiplayer' started by Factoid, Nov 14, 2008.

  1. Factoid

    Factoid

    Joined:
    Mar 30, 2008
    Posts:
    69
    I'm trying to update rigidbody information via an RPC call, and I wanted to know if there is any way to manually update the physics simulation on an object to adjust for lag.
    Code (csharp):
    1.  
    2. function OnCollisionEnter( other : Collision )
    3. {
    4.   if( Network.isServer )
    5.   {
    6.     networkView.RPC( "RPCHandleCollision", RPCMode.Others, rigidbody.position, rigidbody.velocity );
    7.   }
    8. }
    9.  
    10. @RPC
    11. function RPCHandleCollision( pos : Vector3, vel : Vector3, info : NetworkMessageInfo )
    12. {
    13.   rigidbody.pos = pos;
    14.   rigidbody.vel = vel;
    15.  
    16.   var dt = Network.time - info.timestamp;
    17.   // I need to update the physics object here.
    18.   // I could loop it myself, but an API call would be
    19.   // safer, wouldn't it?
    20.   // Otherwise I'd do something like this...
    21.   while( dt > Time.fixedTime )
    22.   {
    23.     rigidbody.pos += rigidbody.vel * Time.fixedTime;
    24.     rigidbody.vel += Physics.gravity * Time.fixedTime;
    25.     dt -= Time.fixedTime;
    26.   }
    27. }
    28.  
    Or is Unity automagically detecting when rigidbodies are affected by network views, and firing off a series of FixedUpdate() calls to compensate?