1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Heat-seeking missile?

Discussion in 'SimConnect' started by Simon853, 5/10/07.

  1. Simon853

    Simon853

    Joined:
    15/1/07
    Messages:
    516
    I'm wondering if it could be possible to add guided missiles to a user aircraft, using an external SimConnect client...

    Basically I think the program would need to be able to acquire a list of all AI traffic items in the sim and identify which one was closest to the user aircraft's boresight. It would then create a non-AI object and "fly" it to the AI aircraft, (or maybe an AI aircraft that could be directed to its target using waypoints.)

    When it reached it, an explosion effect would be triggered, the AI aircraft would be removed from AI control and either deleted or flown down into the ground.

    Do you think this would work? Does SimConnect support such functionality? (I'm relatively new to SimConnect but need a nice little fun project to help teach myself.)

    Si
  2. lc0277

    lc0277

    Joined:
    25/9/06
    Messages:
    156
    Country:
    france
    Some months ago I coded a small prototype software with the same idea in mind. However, the overall work to get a decent result was too heavy and it was not very useful for my flying purposes, so I didn't continue or release it.
    Here are my observations and various things I learned during this:

    - AI targetting / display : definitively not a problem. SimConnect API are pretty fine in this area. Correct integration into a visual radar may need some gauge work, but you can reuse the GPS component which can already draw traffic. SimConnect allows you to create precise data requests, for instance you could request the state of all surrounding aircraft each second, to update the radar display, and once you selected a target or fired your missile, you can create a shorter request for the selected a/c.

    - creation of the missile object is possible and relatively easy within simconnect. Guessing the InitPosition of the object is just geometric calculation from the position and pitch/bank/heading angles of the aircraft. However, even with the smallest period, there is a little lag between the last returned aircraft position and the position of aircraft at the time you will insert the missile. Not a problem with a cessna, but with a 500+ kts fighter, the missile will be fired far behind your jet.
    An alternative is to let FS create the missile object, with the droppable payload features of missions (which can also be used in free flight by writing some SimVariables). Dropped objects are created as AI objects by the sim, so by subscribing to ObjectAdded events, you can get its container ID and continue your work.
    Drawback: you couldn't customise the location where the object is created, thus it will look unrealistic with missile fired from wingtips (F-16, etc)

    A good feature is to modify the visual model of the aircraft to alter the appearance of pods after you launched the missile. This can't be done with simconnect, but with XML panel variables, and it needs an important modification of the 3D model. Surely more easy if you are working with a designer team.


    - Missile flight : There are two main solutions. Either let FS fly the missile as a regular plane, or code your own flight model and use simconnect to send position updates. The FS build-in flight model seems the easiest method, but if you want a decent one, you will need very hard tweaking of .air/.cfg files. IMHO, Flight Dynamics is one the hardest topic in FS addon developing, and especially since FSX has very bare (inexistant?) rocket engine type.
    Coding my own physics engine was the solution I choosed. A missile is definitively not a glider, so you can have drastic simplications on equations. Because of symmetry, I didn't simulate bank angle variations, which are impossible to see while in flight.
    I updated missile position while in slew mode, by sending the appropriate slew events. Slew events data values have a non-linear relationship with the effective velocity, so I used mostly ad-hoc values here. Anyway I wasn't aiming numerical accuracy, a good-looking flight path was enough.

    - Guidance : It depends on the flight model you choosed. If you choosed to let FS fly, you can send waypoints. I didn't used this method and I have doubts on its efficiency. FS autopilot tends to be very gentle, and you can't be assured of reaching near exactly your target just by setting a waypoint in space. I presume this can be tweaked by AP values in aircraft.cfg too, it needs more testing.
    As I used a custom flight model, I needed to implement my own guidance systemn, based on a PID corrector. A funny part to do, all I knew on this subject dates back from some courses at college 10 years ago :) I had a LOT of trial-error sessions to guess correct values for the constants.
    The SimConnect code for this part consists mostly of creating data requests for both your missile and its target. Using a SIM_FRAME period gives you a lot of update per second, so you can have very precise guidance to your target.

    - Collision detection : SimConnect provides nothing for this, so you'll have to do it the dirty way, by calculating the 3D distance between watched objects. Anyway that's how REAL missiles trigger explosion mechanism.
    Crash on the ground can however be detected, by watching the content of the "SIM ON GROUND" variable for your missile.

    - Effects insertions : To simulate rocket exhaust, you can use default contrail effect, but it won't work at low altitudes or if the missile is flew in slew mode. You can also affects a smoke effect to the aircraft.cfg file of your missile and trigger the SMOKE event in simconnect.
    There are nice explosions effects provided with FS, but unfortunately no API to launch them. Fixed explosions effects, for instance on ground, can be created by inserting a pseudo AI object, see for example the WaterDrop object in SimObjects/Misc.
    These pseudo-objects have no geometry or visual model and just display the specified effect in sim.cfg.
    Fire effects attached to an object, for example if your target was hit and lost one engine, can also be launched with smoke events, but you'll need to alter the aircraft.cfg of every possible target a/c, and you can only have one smoke effect.
    The mission system provides some more facilities to insert effects in the sim, but I haven't found how to use them in free flight mode. There are some API to communicate between a mission and a simconnect add-on, maybe they can be used here.
    I found another way to insert effect, by hacking FS modules, but this is definitively out of topic here :)


    - HUD target designator : This is a really nice feature which I didn't manage to get working with an acceptable precision. Looks simple, as it is only to guess the projection coordinates of an object in 3D onto a plane, where you know every parameter (eye position, eye vector coordinates, object position). But I never had a perfect box around my target, it was always shifted to some random direction.
    Maybe some deep knowledge of Direct3D projection mechanism would help here.


    Hope it was useful for your project :). It's a good idea to learn simconnect features and capabilities, as you said.
  3. Simon853

    Simon853

    Joined:
    15/1/07
    Messages:
    516
    Thanks for the feedback and your observations. They're very helpful. I may just give it a go but I've thought of a couple of simpler projects I should take a look at first , easing myself in to SimConnect. It's probably not a good idea to bite off more than I can chew at this stage!

    Si
  4. Foiter

    Foiter

    Joined:
    25/3/07
    Messages:
    35
    Country:
    germany
    Good to see someone is playing around similar ideas. I did that long before FSX was out. I started similar project with FS2004 using Peter Dowson's FSUIPC that time and my own D3DX graphics layer intercepting all D3DX Device calls to control FS on-screen graphics, that way I did my own HUD, XML gauge was no solution for that purpose, because it was too slow for that.

    It is now more than just a HUD, I'm simulating different targeting modes, not only boresight, but HMD visor as well. That time it was not possible to create AI objects, so all my missile firing effects were just additional D3DX on-screen sprites.

    BTW, do not bother with internal FS sim engine to guide your missiles, I lost enough time trying to accomplish this and ended up with my own missile simulator using standard Head-Pursuit algorithm where the target position is predicted based on the current position and its velocity.

    Since FSX's SimConnect is out, it is now possible to directly control AI craft's position and velocity. There is however a small glitch during the time AI object is created.

    The problem I'm facing now - is to find the way to hang missiles directly on the aircraft's pilons. The only way to do this is to read aircraft's attitude matrix AND its WORLD coordinates in XYZ out of FSX per simulation and/or graphics frame. Unfortunately (Lat, Lon, Alt) coordinates are not sufficient for that, because you loose the precision during the conversion into World's XYZ even if you do that in DOUBLE.
    So, in order to keep missiles fixed on their pilons there should be the way to read user aircraft's root matrix. THAT IS THE ONLY WAY (!) Unfortunately I'm not able to do that even if have an access to the D3DX device itself. The problem is to catch an event when FS sets the aircraft's matrix via SetTransform() call. And of course the root matricies of all missiles have to be updated on per frame basis. I'm not sure whether the SimConnect implementation is fast enough to update variables of all created AI objects on per frame basis.

    HMD: The drawing precision of all objects in my HMD including waypoints, airborne and on-ground targets, as well as targeting itself is absolute. What I mean to say is that all calculations I perform are based on the current aircraft position, its orientation and the current viewpoint matrix which is set by FS itself. I'm reading part of this information using SimConnect and a part of it from D3DX9 layer. So, for the targeting as well as the guidance the precision loss during the conversion from sperical to cartesian coordinates is no longer the issue. But it becomes a huge problem hanging AI objects onto the aircraft. And this is where I stuck.

    Attached Files:

    • 065.JPG
      065.JPG
      File size:
      64.9 KB
      Views:
      373
    • 072.JPG
      072.JPG
      File size:
      76.9 KB
      Views:
      370
    Last edited: 2/10/08
  5. phlerp

    phlerp

    Joined:
    6/10/08
    Messages:
    3
    Country:
    sweden
    There might be another way.
    It's not ideal but within its limitations I think it might be reasonably a good solution.
    My idea is to embed the weapon models in the aircraft model and by XML-code limit their visibility based on XML-variables set for each pylon. Then these variales can be controlled by an optional C++ program. When a weapon is fired, you just hide it in the aircraft model and replace it with a AI-object in the proximity of where the weapon in the aircraftmodel was placed. It should work fairly well. However I don't know if this would work for any other aircraft than the user aircraft.
  6. Foiter

    Foiter

    Joined:
    25/3/07
    Messages:
    35
    Country:
    germany
    To hide the geometry via certain events is not a problem.
    The problem in this case is small time interval when the AI object is created. The created object stays way behind the aircraft until its sim actually starts to work, or more specificly until the thread actually starts to process its state data via SimConnect.

    In this thread: http://www.fsdeveloper.com/forum/showthread.php?t=11906 I propose general solution to fix this problem ones and for all.
  7. phlerp

    phlerp

    Joined:
    6/10/08
    Messages:
    3
    Country:
    sweden
    I have proposed exactly this in the FSX beta forum, but has so far got no response. I can only hope this will be consider for FS11.
  8. Foiter

    Foiter

    Joined:
    25/3/07
    Messages:
    35
    Country:
    germany
    Hi Phlerp, if you share the same ideas please post to http://www.fsdeveloper.com/forum/showthread.php?t=11906
    I'd really prefer to move the subject further. The more people join the more probable positive outcome would be.

    The thing is the solution I propose actually is not optimal, because I think the Master object must not be the aircraft, but some of its attach points. That has to be discussed.
  9. phlerp

    phlerp

    Joined:
    6/10/08
    Messages:
    3
    Country:
    sweden
    Last edited: 28/5/09
  10. Vitus

    Vitus

    Joined:
    29/11/06
    Messages:
    699
    Country:
    newzealand
  11. mdm248111

    mdm248111

    Joined:
    17/2/09
    Messages:
    1,241
    Country:
    us-northcarolina
    i like the dude's setup with the whole cockpit etc---

    would be awesome to have something like that for a 737
  12. Simon853

    Simon853

    Joined:
    15/1/07
    Messages:
    516
    Very neat indeed!

    Si

Share This Page