2
\$\begingroup\$

i use unity but this question applies for any third person controller or enemy controller.

i need to use foot ik on slopes(any condition and any kind of slope) to place foot on right places. as i considered some important third person games, it seems they only use ik when character is idle and not moving otherwise no ik is applying and leg animations run purely.

i use the same approach and result looks good enough but im looking for applying when character is walking or running.

as i looked, some people disable ik when leg is going up and enable it when its coming down. some other do a raycast from foot bone to the ground to check foot need ik on little distance to ground. but all of these are prototypes and has flaws. can you give me a good approach that works best in all conditions?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ It sounds like you understand the main options and their drawbacks. If there was a simple approach that worked best in ALL situations, those games would probably be using it too. So instead of asking for perfection, try asking for a solution to a specific problem: what one particular flaw of an approach you've found so far can we help you ameliorate? \$\endgroup\$
    – DMGregory
    Feb 28, 2021 at 14:40

1 Answer 1

2
\$\begingroup\$

When I implemented a foot IK system, I used a raycast each frame to determine the position of the ground in front of the foot. I used the raycast for all types of movement and it worked fine for my purposes. Performance shouldn't be an issue if you don't have too many units doing the raycast at once ("too many" depends on your target platform and how hard your game pushes the physics engine). If there might be hundreds of units all simultaneously walking around with IK, you might enable/disable the raycast foot placement based on the distance from the camera (in other words, if the unit is too far away for the player to be able to tell whether their foot IK is accurate, you don't need to perform the raycast).

Obviously, you should use layer masks to ensure the IK raycast only checks your terrain layer (or any other layers containing walkable surfaces)

I found it necessary to start the raycast a little bit above the foot. If you start the raycast right at the foot, but the foot has clipped through the terrain, the raycast won't detect the terrain because it's starting below the terrain. If you start the raycast above the foot, that's not an issue. How far above the foot depends on your specific leg animations and how your terrain is shaped, but a good starting point is the distance from knee to foot. For example, if the character's leg is .5 meters inches from heel to knee, you might start the raycast .5 meters above the foot.

The free "Fast IK" asset on the Unity Asset Store includes an example of combining IK with Mecanim animation. I used a different solution but found it helpful for reference: https://assetstore.unity.com/packages/tools/animation/fast-ik-139972

Unity has a built-in "foot IK" option for humanoid Mecanim animations but they don't really describe it in their documentation and I haven't used it before. If you haven't already looked into it, you should see if it meets your needs.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .