Hi,
Currently, I am using 2D animation with 2D IK. To make the foot IK, I have to adjust the position of the foot target after the frame of the animation. I have tried LateUpdate. Unfortunately, LateUpdate is called after the IK has been applied…
I have already tried many possibilities.
public class IKAnimationPhysics : MonoBehaviour
{
[SerializeField] Transform raycastY = null;
[SerializeField] Transform[] legs = null;
[SerializeField] LayerMask IKLayer = new LayerMask();
private void LateUpdate() {
foreach (Transform leg in legs) {
RaycastHit2D hit = Physics2D.Raycast(new Vector2(leg.transform.position.x, raycastY.position.y),
Vector2.down,
Mathf.Infinity,
IKLayer);
if (hit.transform == null) continue;
if(hit.point.y > leg.position.y)
leg.position = new Vector2(leg.position.x, hit.point.y);
}
}
Thanks in advance for the answers.
Mike