Projectile doesn't interpolate

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:


2157013--142492--PointLight.png

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.

It’s physics enabled, so it might change directions, depending on what I add later.

Here’s the fire command:

[Server]
  public void Fire(bool shouldFire) {
  if (!shouldFire)
  return;
  if (timer > 0)
  return;
  timer = fireTimer;
  Quaternion fireRot = Quaternion.Euler(0, -maximumArcDivergence, 0);
  Vector3 fireDir =  Vector3.forward;
  Vector3 fireDisp = fireDir * projectileDisplacement;
  Quaternion rot = ownerRigidbody.transform.rotation;
  Quaternion invRot = Quaternion.Inverse(rot);
  Vector3 localFireVelocity =
         Vector3.Cross(
  ownerRigidbody.angularVelocity,
  invRot * (transform.position - ownerRigidbody.transform.position) - ownerRigidbody.centerOfMass)
  + (invRot * ownerRigidbody.velocity);
  Vector3 worldFireVelocity = (rot * localFireVelocity) + (transform.rotation * (fireDir * projectileSpeed));
  GameObject projGO = (GameObject)Instantiate(projectilePrefab, transform.position + (rot * fireDisp) + worldFireVelocity * Time.fixedDeltaTime, rot * fireRot);
  Rigidbody projRB = projGO.GetComponent<Rigidbody>();
  if (projRB) {
  projRB.SetDensity(0.02F);
  projRB.velocity = worldFireVelocity;
  }
  NetworkServer.Spawn(projGO);
  }

As you can see, NetworkServer.Spawn() is called only after the projectile’s velocity is set.

I’m installing patch 5.1p1 now. I’ll report back on whether or not that fixes it.

The patch did not fix the problem.

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?

You should not have LocalPlayerAuthority checked for a bullet if the server is setting it’s velocity

1 Like