bone displacement while animating

hello.

when my character is animating in whichever pose, i would like to be able to apply some force and “shove” the model in a certain direction

more detail:

if my character is casting a spell, and then gets attacked while still casting, i want him to react but without breaking his spell animation

i don’t think it can be done with a “getting hit” animation, as i would need “getting hit” animations for every pose and even then i wouldn’t get the desired effect

so, i’m thinking about “distorting” an animation. the idea is to apply a force to the chest bone on my model so that he gets shoved in the direction the force was applied regardless of what animation is currently playing

is this possible? and if so, could someone point me in the right direction ?

You can override bone animation in LateUpdate (by changing their rotation, location, scale). You’d have to run inverse kinematics on the hands and feet (and maybe head) chain, but it’s definitely possible. Something like this might be what you want, with, of course, most of the work done in Realign. The 'net has lots of how-to-do-inverse-kinematics documents to pick from.

function LateUpdate() {
  if ( hitTime > 0 ) {
    chestBone -= chestBone.forward * Mathf.Sin(hitTime); // make the chest jerk back, then forward
    RealignBonesWithChest();
  }
}