New camera API is coming in version 1.11.3:
camera.world_to_screen(world_pos, [camera])camera.screen_xy_to_world(x, y, [camera])camera.screen_to_world(pos, [camera])
-- Place objects at the touch point.
function on_input(self, action_id, action)
if action_id == hash("touch") then
if action.pressed then
local world_position = camera.screen_xy_to_world(action.screen_x, action.screen_y)
go.set_position(world_position, "/go1")
end
end
end
-- Place objects at the touch point with a random Z position, keeping them within the visible view zone.
function on_input(self, action_id, action)
if action_id == hash("touch") then
if action.pressed then
local percpective_camera = msg.url("#perspective_camera")
local random_z = math.random(camera.get_near_z(percpective_camera) + 0.01, camera.get_far_z(percpective_camera) - 0.01)
local world_position = camera.screen_to_world(vmath.vector3(action.screen_x, action.screen_y, random_z), percpective_camera)
go.set_position(world_position, "/go1")
end
end
end
-- Convert go position into screen position
go.update_world_transform("/go1")
local world_pos = go.get_world_position("/go1")
local screen_pos = camera.world_to_screen(world_pos)