I recently asked you how i could pin the feet of my character in worldspace when they touch the ground and you proposed to add a curve in my animations that will determine how pinned each foot is.
While that solution does work, i was wondering if something more generic could be achieved, as i'd always want to pin the feet if they're close enough to the ground.
I could do a raycast of my own, but the grounder script already does that alongside a capsule cast for each foot.
Plus if my raycast differs from the one of the grounder it's possible that i pin a limb when it's supposed to move, which i'd rather avoid. :)
I looked at the documentation and i noticed that i could use GrounderFBBIK.solver.legs[n].heightFromGround; in order to find how far each foot is from the ground.
However, the end result isn't what i hoped for, the distance i get is almost completely unrelated to the height of the foot from the ground and the end result changes a fair bit based on the height offset.
The blue trail is the motion of grounder.solver.legs[n].IKPosition; while the red trail is the motion of grounder.solver.legs[n].IKPosition - new Vector3(0.01f,grounder.solver.legs[n].heightFromGround,0);
The ground is a flat plane, character, trails and everything else except the ground plane is set to layer "IgnoreRaycast", the grounder checks for "Default" and behaves correctly.
Height offset too low (0), character floats
Height offset correct (-0.22)
Height offset too high (-0.33), character sinks into the ground
Using the second image as reference, you can see how in the circled area the heightFromGround matches the animation, despite the foot being almost at peak height (you'd thus expect the red line to be quite far away from the blue one).
This is how the two trails are supposed to look like (i made a raycast of my own):
The red trail is obtained with: grounder.solver.legs[n].IKPosition + new Vector3(0.02f, Vector3.Distance(grounder.solver.legs[n].IKPosition, hit.point), 0);
You can see how the closter the feet are from the ground the shorter the height becomes, since i'm calculating from the center of the foot the two never match.
I also tried IKOffset and stepHeightFromGround, but those did not help either.
What am i doing wrong?