Code:
------------------------------------------------------------------
-- компас для детектируемых объектов
------------------------------------------------------------------
local HALF_PI = math.pi / 2
--EVENT_UNIT_POS_CHANGED
--EVENT_PROJECTED_OBJECTS_CHANGED
function getDistAngle(id)
---LogToChat("getDistAngle")
local projected = id and object.GetProjectedInfo(id)
if not projected then return end
local avatarPos = avatar.GetPos()
--- тут другие координаты - километры чтоли
--local dX = projected.posX - avatarPos.posX
--local dY = projected.posY - avatarPos.posY
local pos = object.GetPos(id)
if not pos or not avatarPos then return end
local dX = pos.posX - avatarPos.posX
local dY = pos.posY - avatarPos.posY
--LogToChat("projected="..math.ceil(projected.posX)..":"..math.ceil(projected.posY))
--LogToChat("avatar="..math.ceil(avatarPos.posX)..":"..math.ceil(avatarPos.posY))
--LogToChat("pos="..math.ceil(pos.posX)..":"..math.ceil(pos.posY))
--LogToChat(" d="..math.ceil(dX)..":"..math.ceil(dY))
local angle = HALF_PI
if math.abs(dY) > 0.01 then
angle = math.atan(dX / dY)
end
--LogToChat(math.ceil(angle*180/math.pi).."")
angle = -mission.GetCameraDirection() - angle + HALF_PI
if angle > math.pi then
angle = angle - math.pi
elseif angle < -math.pi then
angle = angle + math.pi
end
angle = -1*mission.GetCameraDirection()+HALF_PI
local avatarPos = avatar.GetPos()
local playerPos = { x = avatarPos.posX, y = avatarPos.posY }
local height = dY
local width = dX
if height == 0 then
return
end
local winkel = math.atan(width / height)
angle = angle - winkel
if (width < 0) and (height < 0) then
angle = angle + math.pi
elseif (width < 0) and (height >= 0) then
elseif(width >= 0) and (height < 0) then
angle = angle + math.pi
else
end
return projected.playerDistance, angle
--return angle*180/math.pi, angle
end