Animation strength from script

I have a headbob that I want to play at full strength when the run parameter is 1, and not to play at all when the run parameter is 0.
I also have a headroll that I want to play at full strength when the strafe parameter is 1, and not to play at all when the strafe parameter is 0.

The run and strafe parameters could both be 1 at the same time, and they should just both add to each other in that case.

It seems like I need two blend trees, one for headbob and another for headroll, right?

  1. How do I play both at the same time?
  2. How do I use a blend tree to blend between no animation, and max strength? Should I just create a blank animation and use that as one of the blend targets?
  3. The head bob should loop up and down repeatedly, like a sin wave. However, if the character takes a very short step that just starts the bob animation, it should go in reverse from the current point rather than play out. For example, if the entire animation is 1 second, and the user only walks forward for 1/4 of a second, it should play the up part of the animation for 1/4 of a second, then go play the animation in reverse for 1/4 of a second to go back down. How do I do that?
  4. Animations seem to be tied to a particular model. The animation window won’t even let me modify curves unless I first assign it to a model that has an animation controller. But what if I want the same head bob for more than one model?

I can’t respond to the “from script” part of this because - see sig.

Create layer masks and place each head animation onto an additive layer.

Instead of using an animation to create the head bob you could consider one of the physics joints to control the bobbing motion.
https://unity3d.com/learn/tutorials/topics/physics/physics-joints
Another option is to consider IK for the head bobbing, although I think physics in this instance would be more natural and provide the ‘spring back’ to idle/neutral pose you are looking for, easier than IK.

I’ve not dug into animation driven physics as much as I need to, to properly give info on the exact setup for this, just be aware animation and physics will fight for control over an object if both are applied, so R&D is needed for the proper set up.