# Interpolator

> The Interpolator interface of the Client API draws remote entities of one kind smoothly between state updates.

The **`Interpolator`** interface of the [Client API](/docs/client) records numeric, `angle` and `quat` fields of every entity of one kind as state updates arrive, and returns them between those updates for drawing. [`RoomClient.interpolate()`](/docs/client/room-client/interpolate) returns one.

## Instance properties

All are read only.

[`Interpolator.kind` and `Interpolator.fields`](#description)
: The kind and the fields it draws.

## Instance methods

[`Interpolator.get()`](/docs/client/interpolator/get)
: Returns an entity's fields at the client's render time.

## Description

A room sends state updates at its tick rate, which is usually below the screen's frame rate, and an entity drawn from them moves in steps. An interpolator draws remote entities a little in the past, at the client's render time, between the two states around it. Use it for other players, and [`Prediction`](/docs/client/prediction) for the local player.

The render time is the room's estimated tick, from [`RoomClient.serverTick()`](/docs/client/room-client/servertick), less two ticks or 100 ms, whichever is longer. Each input the client sends carries the render time of the last frame drawn, which the room reads as [`connection.viewTick`](/docs/room/connection/viewtick) for lag compensation.

`kind` is the entity kind passed to `interpolate()`, and `fields` is the array of field names passed with it, the ones [`get()`](/docs/client/interpolator/get) returns.

## Examples

### Drawing the other players

A party game interpolates every player's position and heading, and draws each frame.

```ts
// party.ts
import { connect, defineSchema, entity } from "@irtio/client";

const Guest = entity("guest", { owner: "string", x: "f32", y: "f32", facing: "angle" });
const schema = defineSchema({ entities: [Guest] });

const room = await connect("ballroom", { schema });
const guests = room.interpolate(Guest, ["x", "y", "facing"]);

function frame() {
  for (const g of room.entities.all(Guest)) {
    const { x, y, facing } = guests.get(g);
    console.log(g.owner, x, y, facing);
  }
  requestAnimationFrame(frame);
}
frame();
```

## See also

- [`RoomClient.interpolate()`](/docs/client/room-client/interpolate)
- [`Reckoner`](/docs/client/reckoner), for entities the stepper moves
- [State sync](/docs/room/guides/state-sync#on-the-client)
- [Lag compensation](/docs/room/guides/lag-compensation)
