till213 / SkyDolly

Sky Dolly connects with Flight Simulator 2020 and records the flight path and basic instruments for replay.
MIT License
77 stars 9 forks source link

AI aircraft twitches when flying in formation #86

Open aalbertmate opened 1 year ago

aalbertmate commented 1 year ago

Describe the bug AI aircraft twitches when I get closer in formation, while replaying my flight track.

To Reproduce

  1. Recorded the flight
  2. Formation
  3. Replay
  4. Fly WITH formation

Expected behavior The AI should have a smooth movement instead of lagging and twitching.

Application version:

Thank you! FlightSimulator 2023-02-05 12-50-49-457

till213 commented 1 year ago

Yes, this is - unfortunately - known as "aircraft jitter" (since the FS X day even) for AI aircraft, and documented in the "known issues".

The good news: I have some idea (based on some older SimConnect developer forum entries of the "old days" (< MSFS) how to improve AI aircraft replay. Whether it'll work (also with MSFS) we only know once implemented.

I change this into an "enhancement" ticket, as it requires me to write additional code (and the existing code is technically not "defect": it just doesn't work as well - inside MSFS - as expected).

Orishek commented 3 months ago

Any news about this issue? Planes jittering makes close-formation flying terrible :(

till213 commented 3 months ago

Not as far as the AI aircraft jitter is concerned, no. However I have just restarted with implementation of the upcoming Sky Dolly v0.17 - as a general remark.

I am sorry for the delay, but "life has happened" recently.

That being said, I still have some ideas that could improve the AI replay. The AI aircraft "jitter" is by the way a problem known since the FSX days and both due to the "asynchronous nature" of the SimConnect API (but simply being "asynchronous" does not explain the "jitter" alone: "asynchronous" simply means the data comes and goes "a bit later" than the actual request), but perhaps also because MSFS might sometimes "down-prioritise" the processing of SimConnect requests, specifically for AI aircraft.

One published solution back in the days was to use "slew mode", also for AI aircraft. That means you simply give the velocity (direction + speed vector) and the aircraft would constantly move autonomously - until the next velocity is transmitted, pointing the aircraft towards the next desired waypoint (of the recorded path, or e.g. "pointing at a waypoint 2 seconds away").

The problem with "slew": it disables all simulations, so the aircraft won't even react to flap settings, no sound, no visual effects... this could be acceptable for AI aircraft, but not optimal at all. Also, the "slew factor" has to be calibrated to the actual desired "meters per second" (= the desired real world velocity), it has a maximum value of 16383 that corresponds to I don't know what maximum speed etc.

Of course the SimConnect API also offers to modify velocity simulation variables for the aircraft:

https://docs.flightsimulator.com/html/Programming_Tools/SimVars/Aircraft_SimVars/Aircraft_Misc_Variables.htm

but those are in relation to the aircraft local coordinate system. Assuming for now that the X-axis is pointing "forward" (flight direction) then setting VELOCITY BODY X to the desired feet/s would sound promising... but when the aircraft nose was pointing "up" during some landing approach the aircraft would fly "up" as well. What we would want is to set the desired velocity in world coordinates, but those are not even in the documentation anymore (they used to be there, even documented as "writeable", but doing so never had any effect on the aircraft - so I guess Asobo has now updated the documentation accordingly, by simply removing them).

So this is as far as I got - on a theoretical level. But I will keep on looking into this, after having polished a few other existing features (including replay, auto-sample rate and trying different interpolations (different cubic splines)).

till213 commented 3 months ago

Oh and I took great interest in the Airshow Assistant:

https://msfs.touching.cloud/mods/airshowassistant/

The controlled AI aircraft follow smoothly the user aircraft. The difference: this addon works as "in process" addon, that is it runs "within MSFS" itself (but also using the SimConnect API, as it seems).

This could give such in-process addons an advantage in that they are really getting the latest data and are reliably invoked for every "simulated frame" (while Sky Dolly also reacts to the "simulated frame" event there is no guarantee that MSFS will also react in time to the subsequent SimConnect requests - there is "no service guarantee" ;)).