how to set orient and position a destroyer relative to the aircraft carrier ?

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
hanzawa1991
Posts: 74
Joined: Tue Apr 05, 2022 9:05 am

how to set orient and position a destroyer relative to the aircraft carrier ?

Post by hanzawa1991 »

How to set orient and position a destroyer relative to the aircraft carrier by LUA?
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: how to set orient and position a destroyer relative to the aircraft carrier ?

Post by KnightHawk75 »

use World_GetPointFromBearing to get the position you want from location of the carrier\source unit for your destroyer.
http://commandlua.github.io/#World_GetPointFromBearing

use .heading of carrier\source unit to calculate the heading you want applied to the destroyer if want same direction.
Depending on what you may be doing tool_bearing function may be of use as well.

* If going to be a group set of units and carrier is lead then group first, then set the formation setting properties with the offsets from lead unit and relative settings and separations you so desire.
-----

So lets say I have a carrier called MegaMaid she's at lat 1.0 lon 1.0 heading at 358degrees. I want to create a destroyer called SpaceballOne 12nm behind the carrier based on whatever heading she has at the moment, or based just on position.

Code: Select all

 
--local megamaid = ScenEdit_GetUnit({guid="GuidOfCarrierorWhatever"}); -- use if you already have the carrier.
local megamaid = ScenEdit_AddUnit({side="Whatever", type="Ship", DBID=3197, name="MegaMaid", Latitude=1.0,Longitude=1.0,heading=358.0});
local destRadial = (megamaid.heading + 180)%360;  --get's the opposite heading (ie 180d opposite current heading aka rotating)
local destPoint= World_GetPointFromBearing({LATITUDE=megamaid.latitude, LONGITUDE=megamaid.longitude, DISTANCE=12, BEARING=destRadial});
local spaceballone = ScenEdit_AddUnit({Side="Whatever", Type="Ship", Name="SpaceBallOne", DBID="2718", Latitude=destPoint.latitude, Longitude=destPoint.longitude, Heading = megamaid.heading});
This produces a SpaceballOne orientated aft of MegaMaid at 178d at 12nm, heading 358.
If you don't want it true-opposite of the heading, but just position use 180 for destRadial var.
---

Now lets say this is an existing or new group situation. I'm going to proceed as if nothing has been created or grouped yet.

Code: Select all

local megamaid = ScenEdit_AddUnit({side="Whatever", type="Ship", DBID=3197, name="MegaMaid", Latitude=1.0,Longitude=1.0,heading=358.0});
megamaid.group = "MyNewGrouping"; -- add to group/newgroup and this unit will be lead if new group.. 
-- but we're going to pretend we don't know the lead for cases where say you need to figure it
-- out cause it's some existing group vs knowing already like we do here.

local groupLead = ScenEdit_GetUnit({guid=megamaid.group.lead}) -- this happens to be megamaid again in our case.
local theGroup = ScenEdit_GetUnit({guid=groupLead.group.guid}) -- get the actual group object/wrapper.
--lets set a course 10nm out at 358d for the group itself.
local destPoint = World_GetPointFromBearing({LATITUDE=groupLead.latitude, LONGITUDE=groupLead.longitude, DISTANCE=10.0, BEARING=groupLead.heading});
theGroup.course = {[1]={latitude=destPoint.latitude,longitude=destPoint.longitude,description="MyWaypoint 1"}};
theGroup.manualThrottle = "Loiter";
--now we create spaceballone at the location of the lead. there is a wonky reason for this, just do it, we'll move it later. 
local spaceballone = ScenEdit_AddUnit( {Side="Whatever", Type="Ship", Name="SpaceBallOne", DBID="2718", Latitude=groupLead.latitude, Longitude=groupLead.longitude, Heading = groupLead.heading, speed=5});
spaceballone.group = "MyNewGrouping" --add it to the carrier group.
spaceballone.formation = {type="Rotating",bearing=180.0,distance=12.0}; --Always use decimal. 
spaceballone.latitude=spaceballone.formation.latitude --teleport unit to it's auto calc formation spot
spaceballone.longitude=spaceballone.formation.longitude -- teleport unit to it's auto calc formation spot

This produces a SpaceballOne 180d south of the position of (not relative to heading) MegaMaid lead, at ~12nm distance,
it's station will change radically based on heading of lead however since we used rotational.
Use 'Fixed' if you want that effect of just staying 12nm distant and facing same way as lead but don't want it always staying 'behind' the lead. Note that bearing in GetPointFromBearing is an actual bearing, in formation it is positional bearing relative to the lead unit in the group, 180 behind, 90 right,270 left etc.

Hope that helps and gives some idea how you can go about things.
hanzawa1991
Posts: 74
Joined: Tue Apr 05, 2022 9:05 am

Re: how to set orient and position a destroyer relative to the aircraft carrier ?

Post by hanzawa1991 »

KnightHawk75 wrote: Mon Jun 27, 2022 6:06 am use World_GetPointFromBearing to get the position you want from location of the carrier\source unit for your destroyer.
http://commandlua.github.io/#World_GetPointFromBearing

use .heading of carrier\source unit to calculate the heading you want applied to the destroyer if want same direction.
Depending on what you may be doing tool_bearing function may be of use as well.

* If going to be a group set of units and carrier is lead then group first, then set the formation setting properties with the offsets from lead unit and relative settings and separations you so desire.
-----

So lets say I have a carrier called MegaMaid she's at lat 1.0 lon 1.0 heading at 358degrees. I want to create a destroyer called SpaceballOne 12nm behind the carrier based on whatever heading she has at the moment, or based just on position.

Code: Select all

 
--local megamaid = ScenEdit_GetUnit({guid="GuidOfCarrierorWhatever"}); -- use if you already have the carrier.
local megamaid = ScenEdit_AddUnit({side="Whatever", type="Ship", DBID=3197, name="MegaMaid", Latitude=1.0,Longitude=1.0,heading=358.0});
local destRadial = (megamaid.heading + 180)%360;  --get's the opposite heading (ie 180d opposite current heading aka rotating)
local destPoint= World_GetPointFromBearing({LATITUDE=megamaid.latitude, LONGITUDE=megamaid.longitude, DISTANCE=12, BEARING=destRadial});
local spaceballone = ScenEdit_AddUnit({Side="Whatever", Type="Ship", Name="SpaceBallOne", DBID="2718", Latitude=destPoint.latitude, Longitude=destPoint.longitude, Heading = megamaid.heading});
This produces a SpaceballOne orientated aft of MegaMaid at 178d at 12nm, heading 358.
If you don't want it true-opposite of the heading, but just position use 180 for destRadial var.
---

Now lets say this is an existing or new group situation. I'm going to proceed as if nothing has been created or grouped yet.

Code: Select all

local megamaid = ScenEdit_AddUnit({side="Whatever", type="Ship", DBID=3197, name="MegaMaid", Latitude=1.0,Longitude=1.0,heading=358.0});
megamaid.group = "MyNewGrouping"; -- add to group/newgroup and this unit will be lead if new group.. 
-- but we're going to pretend we don't know the lead for cases where say you need to figure it
-- out cause it's some existing group vs knowing already like we do here.

local groupLead = ScenEdit_GetUnit({guid=megamaid.group.lead}) -- this happens to be megamaid again in our case.
local theGroup = ScenEdit_GetUnit({guid=groupLead.group.guid}) -- get the actual group object/wrapper.
--lets set a course 10nm out at 358d for the group itself.
local destPoint = World_GetPointFromBearing({LATITUDE=groupLead.latitude, LONGITUDE=groupLead.longitude, DISTANCE=10.0, BEARING=groupLead.heading});
theGroup.course = {[1]={latitude=destPoint.latitude,longitude=destPoint.longitude,description="MyWaypoint 1"}};
theGroup.manualThrottle = "Loiter";
--now we create spaceballone at the location of the lead. there is a wonky reason for this, just do it, we'll move it later. 
local spaceballone = ScenEdit_AddUnit( {Side="Whatever", Type="Ship", Name="SpaceBallOne", DBID="2718", Latitude=groupLead.latitude, Longitude=groupLead.longitude, Heading = groupLead.heading, speed=5});
spaceballone.group = "MyNewGrouping" --add it to the carrier group.
spaceballone.formation = {type="Rotating",bearing=180.0,distance=12.0}; --Always use decimal. 
spaceballone.latitude=spaceballone.formation.latitude --teleport unit to it's auto calc formation spot
spaceballone.longitude=spaceballone.formation.longitude -- teleport unit to it's auto calc formation spot

This produces a SpaceballOne 180d south of the position of (not relative to heading) MegaMaid lead, at ~12nm distance,
it's station will change radically based on heading of lead however since we used rotational.
Use 'Fixed' if you want that effect of just staying 12nm distant and facing same way as lead but don't want it always staying 'behind' the lead. Note that bearing in GetPointFromBearing is an actual bearing, in formation it is positional bearing relative to the lead unit in the group, 180 behind, 90 right,270 left etc.

Hope that helps and gives some idea how you can go about things.
nice! thx a lot!!
Post Reply

Return to “Lua Legion”