I'd building a platformer and want enemies to fly through the air when they are killed by an explosion (e.g., grenade). Criteria:
- It should happen when they are killed, but not when they're just hurt by the explosion. FYI my existing grenade mechanic creates several shrapnel objects (sprites with bullet behavior) which emanate from the explosion, and when they collide with the enemy they do damage. If the damage is more than the enemy's health, the enemy dies.
- Angle of trajectory should be based on enemy location with respect to the explosion source. I.e., if they're standing on top of a mine they'll fly straight up, but if they're to the side they would fly sideways away from the explosion.
- Speed of trajectory should be inversely related to the enemy's proximity to the explosion source. I.e., the closer they are to the explosion, the higher their flying speed.
- Optional but desired: it would be great if enemies rotated in the air. The hard part with this option would be to make sure they landed correctly given the available animations. I.e., if they landed face down but the dying animation shows them face up.
I did a little trial and error and it looks like the bullet behavior may be a good place to begin, but I'm wondering if someone has an example I can start with?