I was staring at a piece of code in my foot ik solution, which was essentially copied verbatim from the IK Sample. The more I looked at it, the less I understood how it was even working:
float footOffset = leftFoot_->GetWorldPosition().y_ - jackNode_->GetWorldPosition().y_;
leftEffector_->SetTargetPosition(result.position_ + result.normal_ * footOffset);
We measure the Y-Offset from the character root to the foot. When the character is standing straight on level ground, that is something like the length of the entire leg - agreed?
(lets pretend we’re on a 45 degree slope now)
We cast a ray in the direction of the surface normal, and note the point of intersection on the terrain.
Next, we compute the new position for the foot ik target, by starting at the point of intersection, and casting back along the normal, by the Y-Offset, which puts our ik target somewhere near the pelvis!
The more I look at that code, the less I understand how the IK solver is not exploding!
It seems to me, the best place to put that target, would be to start at the point of intersection, and cast back along the surfacenormal by a very small amount equivalent to the height of the ankle (which is where the foot bone begins) !! (I refer to the animated height of the foot, of course).
What am I missing here?