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.

Projectile doesn't interpolate

Discussion in 'Multiplayer' started by SeriousBusinessFace, Jun 12, 2015.

  1. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    The player's guns fire on the client and server, the projectile displays, it's spawned on the NetworkServer...But the projectile jumps from position to position, rather than smoothly interpolating.

    The projectile is a light and a particle system as sub gameobjects of a pivot object. Images:
    New Bitmap Image.png
    PointLight.png
    ParticleSystem.png
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    You must set the projectile's velocity BEFORE NetworkServer.Spawn() is called on the server.
    You should set the NetworkSendRate to zero for a bullet, unless it will change direction during flight.
     
  3. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    It's physics enabled, so it might change directions, depending on what I add later.

    Here's the fire command:
    Code (csharp):
    1.  
    2. [Server]
    3.   public void Fire(bool shouldFire) {
    4.   if (!shouldFire)
    5.   return;
    6.   if (timer > 0)
    7.   return;
    8.   timer = fireTimer;
    9.   Quaternion fireRot = Quaternion.Euler(0, -maximumArcDivergence, 0);
    10.   Vector3 fireDir =  Vector3.forward;
    11.   Vector3 fireDisp = fireDir * projectileDisplacement;
    12.   Quaternion rot = ownerRigidbody.transform.rotation;
    13.   Quaternion invRot = Quaternion.Inverse(rot);
    14.   Vector3 localFireVelocity =
    15.          Vector3.Cross(
    16.   ownerRigidbody.angularVelocity,
    17.   invRot * (transform.position - ownerRigidbody.transform.position) - ownerRigidbody.centerOfMass)
    18.   + (invRot * ownerRigidbody.velocity);
    19.   Vector3 worldFireVelocity = (rot * localFireVelocity) + (transform.rotation * (fireDir * projectileSpeed));
    20.   GameObject projGO = (GameObject)Instantiate(projectilePrefab, transform.position + (rot * fireDisp) + worldFireVelocity * Time.fixedDeltaTime, rot * fireRot);
    21.   Rigidbody projRB = projGO.GetComponent<Rigidbody>();
    22.   if (projRB) {
    23.   projRB.SetDensity(0.02F);
    24.   projRB.velocity = worldFireVelocity;
    25.   }
    26.   NetworkServer.Spawn(projGO);
    27.   }
    28.  
    As you can see, NetworkServer.Spawn() is called only after the projectile's velocity is set.
     
  4. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    I'm installing patch 5.1p1 now. I'll report back on whether or not that fixes it.
     
  5. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    The patch did not fix the problem.
     
  6. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    I think I've narrowed down the problem; interpolation is scaled depending on how close the other players are. Farther players and objects seem to be interpolated less.

    Does anyone know how to change this?
     
  7. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    You should not have LocalPlayerAuthority checked for a bullet if the server is setting it's velocity
     
    SeriousBusinessFace likes this.