Skip to content

Projection — projection

Converts world coordinates to screen coordinates (same space as the 2D canvas). Call from render callbacks (render_2d, render_gui, frame).

Function Returns
projection.to_screen(pos[, ignore_frustum]) Screen sx, sy, or nil when behind the camera / out of view
projection.box(min, max) Box on screen as x, y, w, h, or nil
projection.entity_box(entity_id) Entity hitbox on screen as x, y, w, h (interpolated), or nil

ignore_frustum = true also projects points outside the view (only fails behind the camera) — useful for edge-of-screen indicators.

module:event("render_2d", function(render)
    for _, p in ipairs(world:players()) do
        if not p:is_self() then
            local x, y, w, h = projection.entity_box(p:id())
            if x then
                render.rect(x, y, w, h, render.paint(0xFF4FF2A6):stroke(1, "inside"))
            end
        end
    end
end)
Navigation

Type to search…

↑↓ navigate↵ selectEsc close