Engine
engine.screen_to_world
Client
Projects a 2D screen-space position to 3D world-space coordinates via the active viewport camera
Syntax
local position = 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 = engine.get_resolution()
local position = engine.screen_to_world({resolution[1]*0.5, resolution[2]*0.5}, 100)
engine.print("info", position[1], position[2], position[3])local resolution = engine.get_resolution()
local near = engine.screen_to_world({resolution[1]*0.5, resolution[2]*0.5}, 10)
local far = engine.screen_to_world({resolution[1]*0.5, resolution[2]*0.5}, 500)
engine.print("info", "Near:", near[1], near[2], near[3])
engine.print("info", "Far:", far[1], far[2], far[3])