Team rocket, blasting off at the speed of light!
Added 2017-03-30 23:26:33 +0000 UTCSo, what this does is gets an axis about which you can rotate a bone. That axis is situated such that if you apply positive rotation, the rotation will always go "away" from the damageOrigin. You can ignore the CalcRelativeHitboxTransform stuff - that's just extracting the "get the true origin of this fist hit" thing - and pay attention to the else case, which is just "the position of the thing that hit me."
Why would you want to do this?
Well, what if you, say... uh... wanted to make dudes spin away into the sky, because you hit them so hard that they went into orbit?
https://www.youtube.com/watch?v=T4swp6CDjK4
That said, I think we're cutting the SUPER SPIN INTO ORBIT thing, as funny as it is. This code is ALSO what we use to power our "jiggle the torso when you get hit" logic, though, and that's great and going nowhere. That being why the direction matters so much - we always want to start the jiggle by rotating away from the hit, then jiggling back.
For some context, here's how it looks when we use it on a flinch (ie. to make the enemy jiggle):
First we do the initial calculation, on that initial flinch event: https://pastebin.com/pVM4Lw3T
Then we do the actual bone-modifying in LateUpdate, so that it always hits after Unity's Animation logic is complete, and we're working with post-animation skeletons: https://pastebin.com/auGTaAD3
... you'll also see how the launch works, there. Super simple. Instead of jiggling, we're just spinning. The logic is such that they always stick their landing, which is a BIT weird, but important for avoiding slam-blends between a partial backflip and a "now my head is upright" pose. One of the many reasons it feels a little weird right now.