Interpolation
Last updated
Was this helpful?
Last updated
Was this helpful?
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
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.
To interpolate a property, add the [Smooth]
attribute to its declaration:
To access the interpolated value, by referencing the property in NetworkRender
, you automatically get interpolated values:
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.
To interpolate other types, you can do that using the Interpolator<T>
object.
First, you must include an id in [Smooth]
:
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.