AddUnit with bearing/distance from other unit

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
Parel803
Posts: 962
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

AddUnit with bearing/distance from other unit

Post by Parel803 »

I realize this might look like a stupid question but I'm gonna ask it anyway, my apologize if it is, and disrecard the question.
I can add a unit via LUA on a geo position. Is it also possible to add a new unit with a bearing and distance from a already exiting unit?
For example you wanna have a submarine an hour in the game in 080 at 10 nm from ship X.
If the answer already exists on the forum please redirect me.
with regards
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: AddUnit with bearing/distance from other unit

Post by KnightHawk75 »

While a few extra steps you may also want to check before you call addunit that the given location's elevation and or nonav zone situation is ok for the given unit type being added, assuming that it could apply to your situation, but the basic version:

Code: Select all

local TheBearing = 80; --degree
 local TheDistance = 10; --nm
 local source = ScenEdit_GetUnit({guid="SourceUnitGUID"});
 local pt = World_GetPointFromBearing( {LATITUDE=source.latitude,LONGITUDE=source.longitude,BEARING=TheBearing, DISTANCE=TheDistance} ) 
 local unit = ScenEdit_AddUnit({side='NATO',type='Ship', name='USS BOXER (LHD-4)', dbid=428, lat= pt.latitude, lon= pt.longitude})
 

Parel803
Posts: 962
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: AddUnit with bearing/distance from other unit

Post by Parel803 »

thank you very much,
with regards
Parel803
Posts: 962
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: AddUnit with bearing/distance from other unit

Post by Parel803 »

sorry to ask another question. I put the waypoint on the original track so the new unit is inbound. I made the "TheBearing" and "TheDistance" 0. And than SetUnit with ManualPlottedCourseWaypoint.
My question is if this can be done easier? I do not get it in an easier way working.
with regards
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: AddUnit with bearing/distance from other unit

Post by KnightHawk75 »

I'm not sure I follow exactly. You want newly added unit to directly head toward the source unit?

Code: Select all

 local TheBearing = 80; --degree
 local TheDistance = 10; --nm
 local source = ScenEdit_GetUnit({guid="SourceUnitGUID"});
 local pt = World_GetPointFromBearing( {LATITUDE=source.latitude,LONGITUDE=source.longitude,BEARING=TheBearing, DISTANCE=TheDistance} ) 
 local unit = ScenEdit_AddUnit({side='NATO',type='Ship', name='USS BOXER (LHD-4)', dbid=428, lat= pt.latitude, lon= pt.longitude})
 local newCourse = {}; table.insert(newCourse,{latitude=source.latitude,longitude=source.longitude,description="toward source"});
 unit.course = newCourse;
 
If you wanted it to duplicate the existing source unit's waypoints such that it eventually ends up in same place more gradually...

Code: Select all

 local TheBearing = 80; --degree
 local TheDistance = 10; --nm
 local source = ScenEdit_GetUnit({guid="SourceUnitGUID"});
 local pt = World_GetPointFromBearing( {LATITUDE=source.latitude,LONGITUDE=source.longitude,BEARING=TheBearing, DISTANCE=TheDistance} ) 
 local unit = ScenEdit_AddUnit({side='NATO',type='Ship', name='USS BOXER (LHD-4)', dbid=428, lat= pt.latitude, lon= pt.longitude})
 local newCourse = source.course; --make copy
 unit.course = newCourse; --apply copy
 
Or do it the way you're doing it, or probably other ways too, all up to which works best for you.
Parel803
Posts: 962
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

RE: AddUnit with bearing/distance from other unit

Post by Parel803 »

Great thx for you're help, much appriciated
with regards
orca
Posts: 545
Joined: Wed Nov 06, 2013 4:59 pm

RE: AddUnit with bearing/distance from other unit

Post by orca »

Is it possible to do something similar for a reference point(s)?

I would like to place a reference point(s) at a certain bearing and distance from a moving unit. The twist is that I want the range and bearing to randomly change a little bit every 1hr so that the reference points are repositioned. I want to do this to provide variability/unpredictability for units on missions that use these reference points.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: AddUnit with bearing/distance from other unit

Post by KnightHawk75 »

ORIGINAL: orca

Is it possible to do something similar for a reference point(s)?

I would like to place a reference point(s) at a certain bearing and distance from a moving unit. The twist is that I want the range and bearing to randomly change a little bit every 1hr so that the reference points are repositioned. I want to do this to provide variability/unpredictability for units on missions that use these reference points.

Yes it's entirely possible, and easy enough to adjust them again in an hourly timed event.
Post Reply

Return to “Lua Legion”