How do I spawn another aircraft and give it instructions to follow

Hi there, I’m quite new to this. I found a Python Simconnect interface GitHub - odwdinc/Python-SimConnect: Python interface for MSFS2020 SimConnect.dll and I was wondering if it is possible to spawn another aircraft and make it fly with specific instructions. Like lat, lon, hdg, alt, pitch updated very regularly. Is this possible? And if so how can I do it?

Many thanks

Yes. that’s possible: the various “AI aircraft” functions are essentially what you are looking for:

Either you assign the aircraft a flight plan (-> AICreateEnrouteATCAircraft) or you create an aircraft that flies by itself (“visual flight rules”). You can also send lat/lon etc. coordinates yourself, in which case you have to “release the AI” (-> AIReleaseControl - in order to fully control the aircraft yourself).

Creating an AI aircraft and getting its assigned ID (for further requests) is asynchronous, so after having created the aircraft you want to “listen” to the various events, specifically:

SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID

The answer you get has both your initial client request ID as well as the newly assigned “object ID”.

Some C++ code:

case ::SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID:
{
    SIMCONNECT_RECV_ASSIGNED_OBJECT_ID *objectData = (SIMCONNECT_RECV_ASSIGNED_OBJECT_ID*)receivedData;
    auto it = skyConnect->d->pendingAIAircraftCreationRequests.extract(objectData->dwRequestID);
    if (!it.empty()) {
        Aircraft *aircraft = it.mapped();
        aircraft->setSimulationObjectId(objectData->dwObjectID);
       ...

Once you have this “object ID” you can then continue with all other requests (e.g. “Release AI”, assign flight plan or send your own position updates etc.)

Note that if you want to set the AI aircraft’s position yourself you need to create it with SimConnect_AICreateNonATCAircraft (and “release AI”). But also take note that once you have released the AI (and perhaps also “freeze” the aircraft ( KEY_FREEZE_LATITUDE_LONGITUDE_SET, KEY_FREEZE_ALTITUDE_SET, KEY_FREEZE_ATTITUDE_SET → refer to SDK Documentation) you basically need to update the position every simulated frame - otherwise the aircraft will just “stand still” in the air.

And that is the tricky part with which I am currently fighting, too (especially if you have recorded position/attitude/velocity data which might already contain "recorded jitter movements). But even when the original data has been sampled at only 1Hz I get “jittering AI aircrafts” - so the problem is probably both “non-smooth/jittery recorded data” in combination with "delayed request messages…

→ If you find a way for smooth playback of AI aircrafts - let us know here! (I am not the only one facing this issue currently ;))

I hope that gets you started :slight_smile:

1 Like

Thank you, that’s very helpful. Much appreciated sir ! :slight_smile: