Obtaining CURRENT user position/attitude of user aircraft

Hi everyone, @EPellissier

I know this is a stretch, and I fully understand the asynchronous nature of SimConnect, but I was wondering if it is possible to obtain position/attitude of user aircraft computed in the current cycle, and applied for the NEXT visual frame?

Currently, position/attitude obtained through SimConnect is for the CURRENT visual frame, and if I use it, it will be 1 frame behind in the next frame update.

Practical use of this “feature” would be attaching SimObjects to user aircraft in real-time and have them follow the user aircraft without lag, for example, cargo crates, or detachable fuel tanks…

1 Like

If this is a WASM project, we found that using this API gets you what’s scheduled for the next frame. Keep in mind that there can always be something (another WASM module) modifying that data after your code is executed.

aircraft_varget(get_aircraft_var_enum("PLANE PITCH DEGREES"), m_Units->Radians, 0)

I know there is a 3rd API for 2024 but I haven’t tried it yet.
SimConnect will always give you some latency on that data.

1 Like

Oh wow - thank you!!

I tried something similar in the past (I think it is the same API) and it seems this is the different way of getting the same data:

#include <MSFS\Legacy\gauges.h>
MODULE_VAR LAT_var = { PLANE_LATITUDE }; 
lookup_var(&LAT_var);

The above code didn’t result in anything useful. I’ll re-visit it and try the call you suggested.

By the same token, is there anything similar ( aircraft_varset() ? ) that would let me inject this data into a SimObject during the current cycle, and avoid the lag using SimConnect_SetData…() ?

Indeed, there are several frames delay between current frame and the frame, when new coordinates received by the child simobject. To solve this, I use the script to calculate “future” position of the aircraft by applying current velocity and rotation velocity (multiplied on 1 or 2 frames length in seconds) to the current position and attitude. It’s not perfect as creates some deviation during intensive aircraft control or acceleration/deceleration, but works. I use aircraft_varget mentioned above, so you still need this kind of calculations anyway.
AirshowAssistant uses such custom parenting script for smokes, refueling accessories and many other things, in case you need to test it. Free demo available on the website.

2 Likes

Please vote the proposal made in 2021 for an Attach API

Using the native model attachment in the model .xml files, compared to constantly setting the position for each attached object, has a dramatic positive effect in performances (perfect attachments with zero lag) and system load and Simconnect traffic, but of course it can’t be done programmatically, that’s why an API would be useful, you can imagine what the impact (and the lag) would be, if every add-on tried to keep several objects attached at each frame.

4 Likes

Umberto a question for you

I’m spawning and moving Simobjects with simconnect
I have ModelAttachements to them (some characters)
In 2020 they work correctly
In 2024 the attached characters are there, but their animation is not playing. Did you experience the same? Any clue? This is in the beta btw

1 Like

Right - a state vector with predictive positioning based on frame rate (and thus time) history. I was going to do that next. Thanks!

Does anyone know how Capt. Sim did their C-130 cargo drop? It seems to be sitting perfectly steady in the cargo bay, and then pulled out via parachute, followed by a perfect landing right where the ground level is… which doesn’t look like a baked-in animation, although all the animations of the cargo getting pulled out of the cargo bay look identical.

It’s possible they switch from an animation to a standalone model and made the transition seamless. That’s how I’d do it!

1 Like

That’s exactly what I was thinking - if the baked-in anim slows down, perhaps to zero lat lon velocity, then the spawn/hide trick at that place would look seamless. But, for that to happen, the plane has to fly at exactly the same speed as the baked-in anim slowdown (actually, a crate speed-up from model’s perspective). So only one speed would work for this to look seamless, unless they can control in-model anim speed.

I just voted. That is exactly what I … heck, WE!! needed.

Very likely in a similar way to how we did Seated Passengers in GSX:

They are “ModelAttachments” for the whole flight (so we don’t have to code anything or generate any traffic to keep them glued with the airplane for the whole flight), with a Visibility check that would make them invisible during Boarding/Deboarding, which is performed with standard Simconnect commands, it’s just a matter of synching the switch between the two models as seamless as possible.

Right, that’s for the objects fixed to the aircraft all the time - but releasing the cargo out of the cargo bay in-flight, and having it drop to earth under parachute, and doing it all seamlessly, - that was done quite well, I haven’t seen even a hint of transition. Mind you, I watched their video, I haven’t purchased the plane to investigate it further.

Very interesting topic… about a year ago I was working on a very similar project that was going to do exactly what the OP is asking, but reached the same conclusion - that it cannot be done, due to the inability to obtain the position of the user aircraft location and orientation for the next visual frame. I had a forum post in the general MSFS Forum site, with some screenshots of the work in progress.

I did actually make use of my code/findings, but only for slow moving objects. I implemented it on our Kennedy Space Center scenery, with NASA’s Crawler Transporter SimObject (GroundVehicle) acting as a "leader, and 3 SimObjects (launch pad, launch tower and rocket) acting as “followers”. It works quite nicely, but only if moving slow. Even slow movement introduces slight shifts, which are tolerable.

But yes, the API that expands to SimConnect would be a game changer. I have developed a physics library that allows for object attachments and used it for our SpacePort demo for P3D:

And this code works perfectly - the rocket you see in the video consists of 13 separate SimObjects all held together using physics library’s fixed joints. I can break those joints dynamically and objects fall off (or fly off if they are powered). The reason I could have done that is, the main user object is the space capsule, and I used SimConnect’s FREEZE functionality to override FS’s flight model. So, that way, I had the control of capsule’s flight model - not sim. And I was giving it the position/orientation.

In any case, if it was possible to do this on sim-controlled aircraft, this physics library would be ready to go, implementing a full SimObject attachment/detachment, and a full physics handling of detached objects, free fall or powered. This would enable all kinds of possibilities… fully pilotable X-15 carried and dropped from B-52 scenario, proper passengers/pilots/cargo, droppable objects (fuel tanks and cargo crates) , aircraft-launched satelite rockets… and obviously, that application everyone wants to see on MSFS202x, but no one wants to admit :wink: : full, proper implementation of guided/unguided/freefall/powered aircraft weaponry!

Mitch
TerraBuilder

2 Likes

This would be a game changer. Voted.

1 Like

I assume you implemented this with linear and angular velocity predictor. Have you considered going one step further and included their derivatives, linear and angular accelerations? I think that may close the little gaps, because that is exactly when they manifest, during the sudden changes in speeds (acceleration/decceleration). I considered trying this but haven’t gotten around it yet.

Mitch
TerraBuilder

There’s already an add-on doing that, but of course it won’t be accepted on the Marketplace, maybe adding an API that would make this even easier is seen as too much…

It’s a pity, because the main reason why we request for new APIs, is mostly for efficiency reasons, to do things in a cleaner and better performing way, to the benefit of the whole system.

Hi,

There is? Sorry - I wasn’t aware… What add-on is that?

yeah that’s just velocity. you may be right that applying acceleration values will make it perfect, but I use it mostly for exterior attachments - aerobatic smoke, refueling pods. it works fine for such needs as no high precision required, until it’s not placed inside of the cockpit.

btw things get worse in FS24, at least I wasn’t able to find solid workaround. the cost of multithreading.

2 Likes

I’ve searched far and wide, and there is no such add-on. I think @Umberto67 meant the cosmetic weapons (which MS appears to now be allowing in MP), and not fully functional, detachable, guided, exploding, etc. as in DCS.