Page 1 of 1

AddUnit with bearing/distance from other unit

Posted: Mon Jul 13, 2020 12:35 pm
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

RE: AddUnit with bearing/distance from other unit

Posted: Mon Jul 13, 2020 2:36 pm
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})
 


RE: AddUnit with bearing/distance from other unit

Posted: Mon Jul 13, 2020 2:51 pm
by Parel803
thank you very much,
with regards

RE: AddUnit with bearing/distance from other unit

Posted: Mon Jul 13, 2020 3:59 pm
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

RE: AddUnit with bearing/distance from other unit

Posted: Mon Jul 13, 2020 8:15 pm
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.

RE: AddUnit with bearing/distance from other unit

Posted: Tue Jul 14, 2020 12:21 pm
by Parel803
Great thx for you're help, much appriciated
with regards

RE: AddUnit with bearing/distance from other unit

Posted: Fri Jul 17, 2020 6:48 pm
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.

RE: AddUnit with bearing/distance from other unit

Posted: Fri Jul 17, 2020 10:31 pm
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.