Bone rotation from view angles

I’ve got a first person character controller script sort of working at the moment. The problem I’m running into, is when I move the sticks vertically, the head and body bones of the model I’m trying to bend end up rotating in the opposite direction…

Why is this happening? (see pic below) The head should be turned down, and not up.

This is the line in the script that turns the bones:

for(int count=0;count<lbones.Length;count++)
		{
			lbones[count].transform.rotation = lOrigRots[count]*Quaternion.AngleAxis((headRotY/lbones.Length),Vector3.up);
		}

lbones is a list of the bones that I have defined that need bending.
lOrigRotes is a list of the original Quaternion angles of the model in resting position.
headRotY is a local variable that tracks the rotation along the y axis gathered by the input axes.

I think it’s probably because every other bone’s rotation is offset by 180 degrees in a skeletal chain. Since I’m writing this script to be modular, and work with any skeletal chain, how do I determine which bone will be rotated backwards, and which will be rotated forwards?

If the bone is within a hierarchy, you will probably want to use transform.localRotation to set its orientation relative to the parent.

Yeah, I actually subbed that code in earlier, but it’s still inverting the local transformation for every other bone in the heirarchy, and unfortunately, there’s no way to tell if the bone you are grabbing is an even or an odd, that I know of.

I’ve had to attach Locator bones to everything I want to animate, due to Blender exporting vertical bones unpredictably. I’ll just add an empty gameobject at the bone’s position, parent the bone to it, parent it to the bone’s old parent, and move the Locator instead of the bone itself.

I wish there were a way to tell Unity that “this” rotation should be considered the default rotation.