Introduction
Two bone IK
is always used for arm IK solve. That is to say, the triangle Hand-Elbow-Arm
is solved using Law of Cosines.
The hand bone of our character is always located, however, at position of the wrist of character mesh like this:
But we don’t directly place this bone to the Left Hand Target
socket of the weapon mesh, or else:
The palm bone of left hand should be constrainted to Left Hand Target
of the weapon mesh. So, we need to solve Arm-Elbow-Hand-Palm
chain.
As a result, default Two Bone IK
node cannot meet our requirement. We need our own anim node.
Why doesn’t Two bone IK
work?
We need a valid location of Left Hand Bone
calculated by:
which is the matrix of palm target, and $M_{LeftPalm}^{-1}$ is the inverse of the local transform of Left Palm
bone.
Of course we can calculate $M_{LeftPalm}^{-1}$ in the Event Graph
or somewhere else. But this is the local transform from previous frame, which might be different of that in current frame.
In short, we need to get this inverse matrix when this AnimInstance
get evaluated. To achieve that, I simply created a new anim node.
Key Logic
The implementation is truly easy because we just need to apply a inversed transform to the Effector
before a AnimationCore::SolveTwoBoneIK
is called.
Thus we just need to get the socket or bone local transform, and apply its inversed value to the current EffectorTransform
.
1 | EffectorTransform = holdingPointLocalTransform.Inverse() * EffectorTransform; |
We can set the palm bone or socket for this node like this:
And this is what we eventually have: