Skip to content

prediction

Vanilla-accurate movement physics: “where will this player be in N ticks?”.

  • Local player — simulated from real input
  • Other players — input guessed from observed motion

Simulations are cached per client tick and stepped lazily (asking for tick 5 then 8 only simulates three more ticks). Queries past tick 1199 return nil (1200 is the exclusive cap).

Function What it does
prediction.self(ticks) Your snapshot ticks ticks ahead (0 = now)
prediction.self_path(from, to) Array of your snapshots for [from, to]
prediction.self_with_input(input, ticks) One-off simulation with a custom held input
prediction.player(entity_id, ticks) Another player’s snapshot
prediction.player_path(entity_id, from, to) Array of another player’s snapshots
prediction.velocity(entity_id) De-smeared per-tick velocity as vec3

A snapshot is {pos, velocity, min, max, on_ground, fall_distance, horizontal_collision}pos, velocity and the min/max bounding-box corners are vec3.

input for self_with_input is {forward, backward, left, right, jump, sneak, sprint} booleans — omitted keys are false.

Remote players’ network positions are interpolated, so raw per-tick delta is unreliable. prediction.velocity returns the recovered true motion and is what the simulation seeds from.

module:event("render_3d", function(render)
    for _, p in ipairs(world:players() or {}) do
        if not p:is_self() and p:distance() < 20 then
            local s = prediction.player(p:id(), 10)
            if s then
                render.box(s.min, s.max, 0x80FF4040, 2)
            end
        end
    end
end)
Navigation

Type to search…

↑↓ navigate↵ selectEsc close