core.engine.screen_to_world
Client
Projects a 2D screen-space position to 3D world-space coordinates via the active viewport camera
Syntax
local position = core.engine.screen_to_world(
position,
depth = 1
)Parameters
| Type | Name | Description |
|---|---|---|
vector2 | position | 2D screen-space pixel coordinates to convert to 3D world-space coordinates |
float | depth | Distance in world units along the camera ray to retrieve the world position |
Returns
| Type | Name | Description |
|---|---|---|
vector3 | position | 3D world-space position at the given depth or {-1, -1, -1} if off-screen |
Examples
local resolution = core.engine.get_resolution()
local center = {resolution[1]*0.5, resolution[2]*0.5}
local position = core.engine.screen_to_world(center, 100)
core.engine.print("info", "World position:", util.table.unpack(position))local resolution = core.engine.get_resolution()
local center = {resolution[1]*0.5, resolution[2]*0.5}
local near = core.engine.screen_to_world(center, 10)
local far = core.engine.screen_to_world(center, 500)
core.engine.print("info", "Near:", util.table.unpack(near))
core.engine.print("info", "Far:", util.table.unpack(far))