function tick() --Raycast forwards local t = GetCameraTransform() local dir = TransformToParentVec(t, {0, 0, -1}) local hit, dist, normal, shape = QueryRaycast(t.pos, dir, 10) DebugWatch("Hit", hit) if hit then --Visualize raycast hit and normal local hitPoint = VecAdd(t.pos, VecScale(dir, dist)) DebugLine(VecAdd(t.pos, {0, -1, 0}), hitPoint, 0, 1, 0) DebugLine(hitPoint, VecAdd(hitPoint, normal), 1, 0, 0) DrawShapeOutline(shape, 1, 1, 1, 1) DebugWatch("Point", hitPoint[1] .. ", " .. hitPoint[2] .. ", " .. hitPoint[3]) DebugWatch("Shape", shape) end end function draw() --Query point closest to camera on dynamic bodies local t = GetCameraTransform() QueryRequire("dynamic") local hit, point = QueryClosestPoint(t.pos, 10) if hit then --Display dot and text on screen local x,y,d = UiWorldToPixel(point) --If d is negative point is behind camera if d > 0 then UiTranslate(x, y) UiAlign("center middle") UiImage("ui/common/dot.png") UiTranslate(0, 20) UiFont("regular.ttf", 20) UiText("loc@TXT_CLOSEST_POINT") end end end