Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getUnitPos(unitName)
- local unit = Unit.getByName(unitName)
- local unitPos = nil
- if unit ~= nil then
- unitPos = unit:getPosition()
- end
- return unitPos
- end
- function getDistance(unit1, unit2)
- local dist = nil
- local pos1 = getUnitPos(unit1)
- local pos2 = getUnitPos(unit2)
- if pos1 ~= nil and pos2 ~= nil then
- local px = pos1.p.x
- local pz = pos1.p.z
- local zx = pos2.p.x
- local zz = pos2.p.z
- dist = math.sqrt( (px - zx)^2 + (pz - zz)^2 )
- end
- return dist
- end
- function getBRA(unit1, unit2)
- local BRA = nil
- local pos1 = getUnitPos(unit1)
- local pos2 = getUnitPos(unit2)
- if pos1 ~= nil and pos2 ~= nil then
- local px = pos1.p.x
- local pz = pos1.p.z
- local zx = pos2.p.x
- local zz = pos2.p.z
- local dx = zx - px
- local dz = zz - pz
- BRA = math.atan2( dz, dx ) * 180 / math.pi
- if BRA < 0 then
- BRA = 360 + BRA
- end
- end
- return BRA
- end
- local dx = zx - px
- local dz = zz - pz
- -- http://stackoverflow.com/questions/1311049/how-to-map-atan2-to-degrees-0-360
- dir = math.atan2( dz, dx ) * 180 / math.pi
- if dir < 0 then
- dir = 360 + dir
- end
- local dist = getDistance("Pilot #1", "Pilot #2")
- trigger.action.outText('Distance: ' .. dist, 5)
- local BRA = geBRA("Pilot #1", "Pilot #2")
- trigger.action.outText('BRA: ' .. BRA, 5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement