Interpolation
Netick runs at a fixed-time step, the same as the Time.fixedDeltaTime
of Unity, which you can specify in the Project Settings. Because of that, the motion of network objects will appear unsmooth and jittery. The reason for this is that, usually, your update rate (render rate) is way higher than your fixed network tick rate. The solution to this problem is called interpolation, which means filling in the gaps between these fixed-time steps/ticks:

So, for example, at tick 6, the value of a network property is 2.0. And at tick 7, it becomes 3.0. Since there are 5 frames between two ticks, the values at each frame would be:
Frame 1: 2.0 — Beginning of tick 6
Frame 2: 2.25
Frame 3: 2.5
Frame 4: 2.75
Frame 5: 3 — End of tick 6, beginning of tick 7
Interpolation of Network Transform
For moving objects, this is important to deal with. Every NetworkTransform has a slot for a Render transform, which is basically the smoothed/interpolated mesh of the object, while the parent would be the simulated/non-interpolated object.
So, you must break your moving objects into a parent (which has the NetworkTransform), and a child which is the interpolated object, and has the mesh/s. Then you specify that child in the Network Transform Render Transform property in the inspector. Check the samples if you are confused.
Interpolation of Network Properties
To interpolate a property, add the [Smooth]
attribute to its declaration:
[Networked][Smooth]
public Vector3 Movement {get; set;}
Accessing Interpolated Values
To access the interpolated value, by referencing the property in NetworkRender
, you automatically get interpolated values:
public override NetworkRender()
{
var interpolatedValue = Movement;
}
Interpolation is implemented by Netick on these types:
Float
Double
Vector2/Vector3
Quaternion
Other types just return the From snapshot between the two snapshots being interpolated.
Interpolation of Other Types
To interpolate other types, you can do that using the Interpolator<T>
object.
First, you must include an id in [Smooth]
:
[Networked][Smooth(6)]
public MyType SomeProperty {get; set;}
And to access the interpolated value, you first need to acquire a reference to the Interpolator object, through which you can get the From and To values, and the Alpha, which you use to interpolate the property.
public override NetworkRender()
{
var interpolator = FindInterpolator<MyType>(6);
var from = interpolator.From;
var to = interpolator.To;
var alpha = interpolator.Alpha;
var interpolatedValue = LerpMyType(from,to,alpha);
}
private MyType LerpMyType(MyType from, MyType to, float alpha)
{
// write the interpolation code here
}
Last updated
Was this helpful?