I've been trying for months to get AI planes in my FSHostClient program to move smoothly, and I've about decided it isn't possible with SimConnect. I challenge anyone here, or anyone from Microsoft, to show me an example of the local user's FSX plane flying alongside a SimConnect AI plane where the AI plane is moving smoothly instead of jumping forward and backward. 
FSHostClient is basically a SimConnect app that the user runs alongside FSX to relay data packets between FSX and an FS2004 DirectPlay (FSHost) session. So as other planes in the session move, they send their FS2004 DirectPlay "velocity" packets to FSHostClient, which then decodes the data and uses it to move an AI plane in the local user's FSX session so he can see them. I have to use AIReleaseControl() and AICreateNonATCAircraft() to make the AI plane have any chance of moving smoothly. This essentially means that the plane is in "slew" mode, or in other words, it's completely still with no movement of its own, and I have to step it forward a little bit at a time, every 25 ms, so it looks smooth. Since I get velocity packet updates from the other players a few times per second, I use their last known velocity and heading info to predict their movement along the same path between updates.
So I was wondering, is it the way I'm decoding the DirectPlay velocity packets? Is it the way I'm predicting the movement? As a test, I setup FSHostClient to update the AI plane every 25 ms like it normally does, but I changed the velocity packet updates from FS9 to only be every 5 seconds, and made it beep when it does these FS9 updates. So I see the AI plane moving with my predictions, and then every 5 seconds I hear a beep and the plane shifts slightly to the "real" position from FS9.
I recorded some video files, and uploaded them to my web site. They're really bad video quality, but it doesn't matter because they're small, and they're enough for you to see what's happening.
Ok, first, here's what it looks like when I'm just flying next to the AI plane -- you can see the AI plane jumping around a lot, and you can hear the beep every 5 seconds when the AI plane is moved to the "real" location using the FS9 packet:
http://www.chocolatesoftware.com/fshost/misc/fsx_fly.avi
And then the same thing but this time I'm slewing next to the AI plane (which is to the right of me this time) -- the jumping around is about the same, which you would expect:
http://www.chocolatesoftware.com/fshost/misc/fsx_slew.avi
Ok, now, something interesting... This video starts out flying and then after a couple of seconds I hit the pause button. Then you see the AI plane fly away from me, but notice how smooth it is!
http://www.chocolatesoftware.com/fshost/misc/fsx_fly_pause.avi
And then the same thing, but slewing first and then pause -- about the same as flying and pausing:
http://www.chocolatesoftware.com/fshost/misc/fsx_slew_pause.avi
Now... I remember a while back, Joel DeYoung was telling me that if you're flying next to an AI plane there's a bit of an optical illusion happening. The AI plane is completely still, but then it hops forward every 25 ms. If your plane is flying next to it, then in the time between 25 ms updates, your plane is moving forward but the AI plane is still, so it appears as though the AI plane is moving backwards. Then the AI plane hops forward again at the next 25 ms update. What you end up seeing is the plane drifting smoothly backwards, then jumping forwards, then drifting back, jumping forwards, over and over. Did you notice that all the jumping around was only forward-backward? There was hardly any side-to-side jumping. But if you pause your plane, or if you're sitting on the ground watching the AI plane, then there's no optical illusion and the movement is smooth.
Now, here's a video using FS9, with FSHost controlling an AI plane. It's the same type of thing, but FSHost is doing the AI plane instead of FSHostClient, and instead of creating an AI plane directly inside FS9 like we do with FSX, it's creating the plane and then sending in velocity packets to the session every 250 ms. But watch how smooth it is:
http://www.chocolatesoftware.com/fshost/misc/fs9_pace_fly.avi
So why doesn't it happen in FS9? Because when we create AI planes in FS9 we tell the AI plane to start moving in a particular direction, and then give it updates every once in a while. But in between updates, the AI plane keeps moving on its own. It's exactly how the multiplayer system works in FS9 -- each plane tells everyone else their current location, heading, velocity, etc., and then the other players draw an AI plane there, and FS9 keeps it moving automatically until it gets a new velocity packet. This isn't possible in FSX, so we have to use slew mode and hop the AI plane forward a step at a time. And I think that's what's causing the optical illusion, and the jumping around.
If that's the case, then it's not a problem with my decoding of the velocity packets. You can hear the beeps in the videos every 5 seconds when it gets a new velocity packet from the other player and jumps the plane to the correct location -- there's a bit of a shift in position, but not that much, and it's a lot less with the normal 250 ms data updates. So my predictions are fairly accurate.
And it's also not my predictions causing it to look jumpy. Because when my plane is paused, the AI plane moves very smoothly as it flies away from me. I've seen this also when I did a test where the AI plane was moving slowly on the ground -- very smooth.
So the question is, how do we fix the optical illusion?
One thing I tried was to update the AI plane at the same rate that the FSX plane was updating visually. I was hoping I could get them in sync that way, so they essentially moved forward at the same times. I changed the rate at which I was getting data from FSX to use "SIMCONNECT_PERIOD_VISUAL_FRAME" (instead of SIM_FRAME, which I normally use) and then updated the AI planes each time I got a data callback, but it didn't help.
The other thing I tried was to update the AI plane much more often, like 1000 times per second instead of every 25 ms. It had only a very slight improvement, but not nearly enough to make it worthwhile to update the plane that often.
So if the local FSX user isn't moving, the AI planes look great. But when flying alongside the AI planes, they look terrible. And somehow this doesn't happen when you have two FSX planes flying together using the built-in multiplayer system -- my guess is because FSX itself is updating both the local user's plane and the AI planes and it's keeping them in sync. But I haven't found a way to do that through SimConnect.
Has anyone been able to make this work with SimConnect? So far I've talked to two other developers that have tried but have given up in disgust. I'm about at that point also, but thought I might appeal to this forum to see if anyone had any ideas.
Thanks,
Russell Gilbert
FSHostClient is basically a SimConnect app that the user runs alongside FSX to relay data packets between FSX and an FS2004 DirectPlay (FSHost) session. So as other planes in the session move, they send their FS2004 DirectPlay "velocity" packets to FSHostClient, which then decodes the data and uses it to move an AI plane in the local user's FSX session so he can see them. I have to use AIReleaseControl() and AICreateNonATCAircraft() to make the AI plane have any chance of moving smoothly. This essentially means that the plane is in "slew" mode, or in other words, it's completely still with no movement of its own, and I have to step it forward a little bit at a time, every 25 ms, so it looks smooth. Since I get velocity packet updates from the other players a few times per second, I use their last known velocity and heading info to predict their movement along the same path between updates.
So I was wondering, is it the way I'm decoding the DirectPlay velocity packets? Is it the way I'm predicting the movement? As a test, I setup FSHostClient to update the AI plane every 25 ms like it normally does, but I changed the velocity packet updates from FS9 to only be every 5 seconds, and made it beep when it does these FS9 updates. So I see the AI plane moving with my predictions, and then every 5 seconds I hear a beep and the plane shifts slightly to the "real" position from FS9.
I recorded some video files, and uploaded them to my web site. They're really bad video quality, but it doesn't matter because they're small, and they're enough for you to see what's happening.
Ok, first, here's what it looks like when I'm just flying next to the AI plane -- you can see the AI plane jumping around a lot, and you can hear the beep every 5 seconds when the AI plane is moved to the "real" location using the FS9 packet:
http://www.chocolatesoftware.com/fshost/misc/fsx_fly.avi
And then the same thing but this time I'm slewing next to the AI plane (which is to the right of me this time) -- the jumping around is about the same, which you would expect:
http://www.chocolatesoftware.com/fshost/misc/fsx_slew.avi
Ok, now, something interesting... This video starts out flying and then after a couple of seconds I hit the pause button. Then you see the AI plane fly away from me, but notice how smooth it is!
http://www.chocolatesoftware.com/fshost/misc/fsx_fly_pause.avi
And then the same thing, but slewing first and then pause -- about the same as flying and pausing:
http://www.chocolatesoftware.com/fshost/misc/fsx_slew_pause.avi
Now... I remember a while back, Joel DeYoung was telling me that if you're flying next to an AI plane there's a bit of an optical illusion happening. The AI plane is completely still, but then it hops forward every 25 ms. If your plane is flying next to it, then in the time between 25 ms updates, your plane is moving forward but the AI plane is still, so it appears as though the AI plane is moving backwards. Then the AI plane hops forward again at the next 25 ms update. What you end up seeing is the plane drifting smoothly backwards, then jumping forwards, then drifting back, jumping forwards, over and over. Did you notice that all the jumping around was only forward-backward? There was hardly any side-to-side jumping. But if you pause your plane, or if you're sitting on the ground watching the AI plane, then there's no optical illusion and the movement is smooth.
Now, here's a video using FS9, with FSHost controlling an AI plane. It's the same type of thing, but FSHost is doing the AI plane instead of FSHostClient, and instead of creating an AI plane directly inside FS9 like we do with FSX, it's creating the plane and then sending in velocity packets to the session every 250 ms. But watch how smooth it is:
http://www.chocolatesoftware.com/fshost/misc/fs9_pace_fly.avi
So why doesn't it happen in FS9? Because when we create AI planes in FS9 we tell the AI plane to start moving in a particular direction, and then give it updates every once in a while. But in between updates, the AI plane keeps moving on its own. It's exactly how the multiplayer system works in FS9 -- each plane tells everyone else their current location, heading, velocity, etc., and then the other players draw an AI plane there, and FS9 keeps it moving automatically until it gets a new velocity packet. This isn't possible in FSX, so we have to use slew mode and hop the AI plane forward a step at a time. And I think that's what's causing the optical illusion, and the jumping around.
If that's the case, then it's not a problem with my decoding of the velocity packets. You can hear the beeps in the videos every 5 seconds when it gets a new velocity packet from the other player and jumps the plane to the correct location -- there's a bit of a shift in position, but not that much, and it's a lot less with the normal 250 ms data updates. So my predictions are fairly accurate.
And it's also not my predictions causing it to look jumpy. Because when my plane is paused, the AI plane moves very smoothly as it flies away from me. I've seen this also when I did a test where the AI plane was moving slowly on the ground -- very smooth.
So the question is, how do we fix the optical illusion?
One thing I tried was to update the AI plane at the same rate that the FSX plane was updating visually. I was hoping I could get them in sync that way, so they essentially moved forward at the same times. I changed the rate at which I was getting data from FSX to use "SIMCONNECT_PERIOD_VISUAL_FRAME" (instead of SIM_FRAME, which I normally use) and then updated the AI planes each time I got a data callback, but it didn't help.
The other thing I tried was to update the AI plane much more often, like 1000 times per second instead of every 25 ms. It had only a very slight improvement, but not nearly enough to make it worthwhile to update the plane that often.
So if the local FSX user isn't moving, the AI planes look great. But when flying alongside the AI planes, they look terrible. And somehow this doesn't happen when you have two FSX planes flying together using the built-in multiplayer system -- my guess is because FSX itself is updating both the local user's plane and the AI planes and it's keeping them in sync. But I haven't found a way to do that through SimConnect.
Has anyone been able to make this work with SimConnect? So far I've talked to two other developers that have tried but have given up in disgust. I'm about at that point also, but thought I might appeal to this forum to see if anyone had any ideas.
Thanks,
Russell Gilbert





