> For the complete documentation index, see [llms.txt](https://netick.gitbook.io/v1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://netick.gitbook.io/v1/interpolation.md).

# 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:

<figure><img src="https://netick.net/wp-content/uploads/2022/09/interpolation-2-1024x444.png" alt=""><figcaption></figcaption></figure>

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:

```csharp
[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:

```csharp
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]`:

```csharp
[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.

```csharp
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
}
```

{% hint style="info" %}
Note: you should cache the result to `FindInterpolator<MyType>(5)` on NetworkStart, instead of calling it repeatedly every frame (NetworkRender is called every frame), since it might be a bit slow.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://netick.gitbook.io/v1/interpolation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
