Jump to content

Recommended Posts

Posted

Hi - its likely a no, but is there scriptwise a way to retreive the magnetic variance at a units location like fx. (getMagneticDeclination())?

 

Kola map has a pretty large variance in the Magnetic Declination over very short distances, so a constant is not "really" useful.

I could create a table, but that is a very "local" solution and does not lend much freedom in moving the units around afterwards.

Posted (edited)

@Mav87th Have you tried something like:

-- includes
local magvar = require("magvar")
local terrain = require("terrain")
-- taken from /Scripts/utils_common.lua
local function toDegrees(radians)
	return radians * 180 / math.pi
end
-- get unit position
local unit = Unit.getByName("MyUnit")
local p = unit:getPosition().p
-- convert x,y to lat,lon
local lat, lon = terrain.convertMetersToLatLon(p.x, p.z)
-- set month/year from mission
magvar.init(env.mission.date.Month, env.mission.date.Year)
-- get magvar
local mv = toDegrees(magvar.get_mag_decl(lat, lon))
-- pretty print
local txt = string.format("%+0.1f°", mv)
trigger.action.outText(txt, 10)

 

Edited by Chump
Fixed code
Posted
vor 12 Stunden schrieb Chump:

@buur I fixed the code above. I wrote it from memory without testing it late at night. </excuses>  It can be executed in a mission now.

ok, now it works. Thanks for your efforts. Great to know that it is possible to get the magnetic variation.

  • Recently Browsing   0 members

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