Jump to content

Reconocer Objetos


Serginix

Recommended Posts

Hola a todos, tenia una pequeña duda sobre las distancia, y es

¿Como reconocer que objeto es mas Cercano?

Me explico:

Digamos que tengo 3 markers 1 en LS, otro en LV y otro en SF, Ahora en alguna parte del script le indico que obtenga cual es el Marcador mas cercano, entonces

Bueno, creo que se usarian las funciones

x, y, z = getElementPosition (jugador) 
mx, my, mz = getElementPosition ( deLosMarkers) -- con Una Loop para reconecer tooodos los markers que tengan un data que confime que si son de los markers que nesesito 
distancia = getDistanceBetweenPoints2D (x, y, mx, my) 

Bueno, la verdad no sabria como hacer que me identificara cual es el mas cercano, pero se que nesesito de esas 3 funciones, si alguien sabe o me puede ayudar, gracias :)

Link to comment
function getNearestMarkerToPosition(x, y) 
    local minDistance=100000 
    for index, marker in ipairs(getElementsByType("marker")) do 
        local mx, my = getElementPosition(marker) 
        local distance = getDistanceBetweenPoints2D(x, y, mx, my) 
        if (distance) then 
            minDistance=distance 
            return marker 
        end 
    end 
end 

No lo probe.

Link to comment

Ese script no funcionará.

Lo corrijo:

    function getNearestMarkerToPosition(x, y) 
        local minDistance=math.huge 
        local nearestMarker = nil 
        for index, marker in ipairs(getElementsByType("marker")) do 
            local mx, my = getElementPosition(marker) 
            local distance = getDistanceBetweenPoints2D(x, y, mx, my) 
            if (distance<minDistance) then 
                minDistance=distance 
                nearestMarker = marker 
            end 
        end 
        return nearestMarker 
    end 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...