Unity's inverse dynamics IK

1. How to use

(1) Add the IK Manager script to the parent object of the object

(2) Create empty objects at the ends of the character's limb bones and the end of the scepter

 (3) Add IK node

Select Player

After adding, you will find that a sub-object IK node of Player appears.

Drag the GameObject at the end of the scepter into the Effector

 

After setting the ChainLength and creatingTarget, you will find that there are sub-objects in the IK node.

(4) Select the IK node to move

 

(5) After setting the position, set the IK node as a sub-object of the Player to prevent problems when the Player moves.

2. Important parameters

 

 3. Small exercise: Wherever the mouse points, where does the finger point?

public class L39 : MonoBehaviour
{
    //两只手的ik节点(是IK节点的子对象target)
    public Transform rightHandIkPoint;
    public Transform leftHandIkPoint;

    //记录鼠标位置
    private Vector3 mousePos;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButton(1))
        {
            //记录鼠标位置
            mousePos = Input.mousePosition;
            //鼠标的Z轴跟摄像机的Z轴反向,摄像机Z是-10
            mousePos.z = 10;
            //屏幕坐标转世界坐标
            rightHandIkPoint.position = Camera.main.ScreenToWorldPoint(mousePos);
            leftHandIkPoint.position = Camera.main.ScreenToWorldPoint(mousePos);
        }
    }
}

Guess you like

Origin blog.csdn.net/holens01/article/details/131049633