how to set orient and position a destroyer relative to the aircraft carrier ?
Posted: Sun Jun 26, 2022 2:09 pm
How to set orient and position a destroyer relative to the aircraft carrier by LUA?
What's your Strategy?
https://forums.matrixgames.com:443/
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});
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
nice! thx a lot!!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.
This produces a SpaceballOne orientated aft of MegaMaid at 178d at 12nm, heading 358.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});
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.