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.