Interpolator: get() method
Available since
@irtio/client 5.0BrowsersNodeThe get() method of the Interpolator interface returns an entity’s fields at the client’s render time, a little behind the room’s clock, linearly between the two states around it.
Syntax
get(entity)
Parameters
entity- A client entity of the interpolator’s kind.
Return value
An object with each field the interpolator was made with: a number for a numeric or angle field, and a Quat for a quat field.
Exceptions
IrtError- Thrown with the name
InvalidStateErrorif the room has no ticks, once the client has the room’s firstwelcomemessage.interpolate()throws this too, but can’t tell before then, so an interpolator made earlier can reachget().
Description
Call get() once per entity each frame. The render time is the room’s estimated tick less two ticks or 100 ms, whichever is longer.
- An
anglefield goes the short way round where it wraps. - A
quatfield is blended by normalized lerp on the same side as the earlier state, so a rotation whose sign flips between states doesn’t spin. - Past the last state update, it returns that update’s values.
- For an entity the interpolator has no states of, it returns the entity’s own values.
An entity that stood still and starts moving moves from where it rested, not from its last recorded state.
Examples
Drawing a spinning asteroid
Asteroids carry a position and a quat rotation, which the client interpolates for a 3D scene.
// asteroids.ts
import { connect, defineSchema, entity, type Quat } from "@irtio/client";
const Asteroid = entity("asteroid", { x: "f32", y: "f32", z: "f32", spin: "quat" });
const schema = defineSchema({ entities: [Asteroid] });
const room = await connect("belt", { schema });
const asteroids = room.interpolate(Asteroid, ["x", "y", "z", "spin"]);
function place(id: number, x: number, y: number, z: number, spin: Quat) {
console.log(id, x, y, z, spin.w);
}
function frame() {
for (const a of room.entities.all(Asteroid)) {
const { x, y, z, spin } = asteroids.get(a);
place(a.id, x, y, z, spin);
}
requestAnimationFrame(frame);
}
frame();
See also
RoomClient.interpolate()Reckoner.get()Prediction.render(), for the local player
Runtime availability
| Browsers | Node | |
|---|---|---|
get() | 5.0 | 5.0 |