# Calculate animation weights based on two variables

I am working on a custom engine and have been tinkering with animations using the Cal3D library. My previous experience with animations was based on prototyping a bit with Unity's Mecanim.

Right now, I'm trying to implement a character that can be idle, walk or run and is also able to point it's gun straight, up or down while doing any of the previous animations. As far as I know, this would require two different variables from which to calculate the weights of each animation, these are, the aiming angle and the speed of the player.

At first I thought about separating the hands and head of the player as a partial animation and do a 1DBlender (like the one in Unity) based on the aiming angle to interpolate between three different animations of the arms and head pointing up, straight or down. Then, for the rest of the body, interpolate with another 1DBlender based on the speed. While the solution works, I'm still not completely okay with it, as I cannot have blended animations for the arms and head based not only on the aiming angle but also on the speed (which would allo me to have things like having the head of the character slightly bobbing while pointing down and running and then having the head mostly still while idle).

My idea was to try to implement something similar to one of the 2DBlenders found in unity in such a way that I could have 9 animations (IdlePointingDown, IdlePointingUp, IdlePointingStraight, WalkingPointingUp, ...) and calculate the weight for each animations based on the two variables I have. The issue is that I don't have any idea on how to implement such blender. Could anybody give me any tips on what the pseudocode or general idea would be like, or recommend me a different solution?

Thank you very much.

• It's been a while since I've done animation blending, but your fist solution sounds like something that I would try to do. Not sure from what you've written but why can't you have the arms and head blended this way?
– Jay
Apr 15 '19 at 5:32
• Hi Jay, thanks for answering :). My issue with the first method is that (at least how I'm thinking about it), I will have three poses for the head and arms of the player (one pointing up, another straight and one down), which will be blended between them using the aiming angle. The issue I see with this is that I can only have these three animations, if I would like to make the head and arms sligthly move while running and then remain completely still while idle, I would need to calculate the weight based not only on the angle but also on the speed. This is what I don't know how to do. Apr 15 '19 at 12:43