unityIK动画系统和matchyTarget

it2022-05-19  64

unityIK动画系统和matchyTarget

 

一:matchyTarget

 anim.MatchTarget(matchtarget,Quaternion.identity,AvatarTarget.LeftHand,new MatchTargetWeightMask(Vector3.one,0),0.32f,0.4f);

//作用是将骨骼上特点的一些点,在动画播放的过程中的某一个特定时刻,放在自己想放的点上。

//参数1:身体部位将放置到的目标点;参数二:身体部位将旋转的位置;参数三:身体的部件;参数四:匹配位置的权重和旋转的权重;参数五:动画开始剪辑的时间(可以百分比);参数六:身体部位到达的动画时间。

 

二:IK动画的设置

以左右手举例

事先需要为需要的动画层设置骨骼遮障,勾选IKpass等

public Transform lefthand;

public Transform right hand;

private void OnAnimatorIK(int layerIndex)//该函数会一直执行,且传递参数layerindex=勾选IKpass的图层索引 { if (layerIndex==1) { int weight = anim.GetBool("handID") ? 1 : 0; anim.SetIKPosition(AvatarIKGoal.LeftHand,lefthand.position);  //用来设置左手与目标位置的位置 anim.SetIKRotation(AvatarIKGoal.LeftHand, lefthand.rotation); //用来设置左手与目标位置的旋转 anim.SetIKPosition(AvatarIKGoal.RightHand, righthand.position);//同理 anim.SetIKRotation(AvatarIKGoal.RightHand, righthand.rotation);//同理 anim.SetIKPositionWeight(AvatarIKGoal.LeftHand,weight);//用来设置左手到目标位置的权重,0不播放,1完全到达; anim.SetIKRotationWeight(AvatarIKGoal.RightHand,weight);//同理

} }

然后需要在运行游戏的时候去调节事先定义好的俩目标位置,来使手放在该放的位置,调节目标位置会影响下次运行效果,正好利用这一特点;

 

转载于:https://www.cnblogs.com/wenzeBlog/p/7821260.html


最新回复(0)