MaintainFormationPosition

Maintain position in formation

Usage: Used in 8 task(s)

Lua Implementation

-- Maintain Formation Position
function execute(params)
    local leader = params.leader or this:getSuperior()
    local formation = params.formation_name
    local position = params.position

    if leader and leader:isValid() then
        local expectedPos = formationUtils.getFormationPosition(
            leader:getLocation3D(),
            formation,
            position
        )

        -- Move to maintain position
        local currentLoc = this:getLocation3D()
        local distance = spatialUtil.distance(currentLoc, expectedPos)

        if distance > params.tolerance or 50 then
            this:addTask("DtGoto", {location = expectedPos})
        end

        return true
    end
    return false
end