Inspired by the recent work on aircraft damage systems, I decided to create animation of aircraft disintegration upon impact. It is based on Nasal and translate + rotate animations with heavy use of expressions. The basic idea is that aircraft freezes in place when it hits the ground, so I set up animations of aircraft parts continuing the movement, but no longer together They have some initial velocity and follow a parabolic curve until they hit the ground.
For those who don't want to read to the end - you can get my recently (pre)released L-159 ALCA which which features these animations. You can use it as reference implementation as well.
Disclaimer: it is still in the pre-release phase, so no texturing (some changes to the model are planned), no cockpit instruments yet etc.
http://fguk.eu/index.php/hangar/viewdow ... l-159-alca
Teaser video on YouTube (as seen in last newsletter):
Overall design
In the Nasal file, every part/group of parts of the model is initialized with coordinates of its center and some initial disintegration velocity, which should be directed away from the aircraft center. This could be easily randomized, but predefined values worked best for me. This initial disintegration speed is then later multiplied by disintegration severity, obtaining speed finally used for animation.
In the model XML file, one has to include translate and spin animation for every desired disintegration part. The animations read properties initialized by Nasal script and thanks to heavy use of expressions, the translate animations emulate a parabolic flight of each part until a timer set for every part separately stops it. This should result in parts laying on the ground when the surface is flat.
Details of the model can be simply hidden or grouped to one object with part they are placed on.
Upon impact, first thing that is done is a severity calculation. Then certain calculations are made for every disintegration part to set its initial speed and fall time (based on current AGL). Because of this, the animation works well only on approximately flat areas with zero slope. If the severity reaches certain value, explosion animation (and if on the ground, also fire with huge smoke) are triggered.
The disintegrate() function can be called externally by Nasal to emulate in-air disintegration/explosion, forcing custom severity is possible.
How to implement
In Disintegration.nas:
Add calls of the function initPart(name, dX, dY, dZ, vX=0, vY=0, vZ=0) for every part that is supposed to fly on a separate curve.
The Nasal code can be mirrored with some necessary adjustments in the <nasal> <load> </load> </nasal> part of the model XML file to achieve multiplayer support.
In the model XML file:
Include three translate (x,y,z) and up to three optional spin animations for every part.
The name string in the nasal initPart() call must match the property paths used for animation of that specific part in the model XML file. The center offsets dX, dY, dZ must match center of the spin animation. It is convenient to use the <name> animation for all the model pieces flying as one part during disintegration and to keep the name the same as in the nasal initPart() call for the sake of simplicity.
All the animations (especially spin) must be placed after any other animations applied on the parts, preferably as the last part of the model XML file. Spin must always be after the translation of the same part. Not following this will result in spinning around wrong point, which looks absolutely wrong.
All spin animations should include unique coefficients of rotation speed (which get multiplied by global rotation coefficient). This way the animation looks more random and natural.
In case you use separate file eg. for payload on underwing pylons, you may need to include the animations there as well.
For details and the actual code, see example implementation in the fresh L-159 ALCA public pre-release: http://fguk.eu/index.php/hangar/viewdow ... l-159-alca
The Nasal code is well commented, so it should be easy to understand the logic even without detailed study of the calculations used.