IsInFormation

Check if entity is in proper formation

Usage: Used in 8 task(s)

Lua Implementation

-- Is In Formation
function evaluate(params)
    local leader = params.leader or this:getSuperior()

    if not leader or not leader:isValid() then
        return false
    end

    local formationName = params.formation_name or "wedge"
    local position = params.position or 1
    local tolerance = params.tolerance or 50  -- meters

    -- Get expected position
    local expectedPos = formationUtils.getFormationPosition(
        leader:getLocation3D(),
        formationName,
        position
    )

    local distance = spatialUtil.distance(this:getLocation3D(), expectedPos)
    return distance <= tolerance
end