GE Lua Documentation

Press F to search!

getClosestDoorPositionForFacility

Definition


-- @/lua/ge/extensions/freeroam/facilities.lua:157

local function getClosestDoorPositionForFacility(facility)
  local camPos = core_camera.getPosition()
  local center = getAverageDoorPositionForFacility(facility)
  local closest = nil
  local closestDist = math.huge

  for _, pair in ipairs(facility.doors or {}) do
    local obj = scenetree.findObject(pair[1])
    if obj then
      local dist = (obj:getPosition() - camPos):length()
      if dist < closestDist then
        closestDist = dist
        closest = obj:getPosition()
      end
    end
  end
  return closest
end

Callers

@/lua/ge/extensions/gameplay/drag/dragBridge.lua
M.openHistoryScreen = function(facility)
  local dragPos = freeroam_facilities.getClosestDoorPositionForFacility(facility)
  if career_career.isActive() and dragPos then