一、模型制作
使用maya对obj文件的人物进行绑定骨骼与蒙皮:https://www.bilibili.com/video/av37072405/
首先将模型改为T型,因为这样有利于后面设置蒙皮权重。
二、添加武器、摄像机等
1.导入UFPS、Final IK 插件。
2.将预制件HeroHDWeapons拖入到场景。将我们做好的模型替换其子对象Body。
为模型添加组件:Animator(UFPSExampleAniatior)、Vp_FP Body Animator、Full Body Biped IK。
3.将Body下的weapons复制到模型的RightHand下,并分别将每个武器调整到相对模型左手合适的位置。
4.之所以使用Final IK的组件是因为使用Michael的模型替换后,左手位置在原有动画下位置错误,也方便以后对动作进行修改。
对需要两只手拿的武器,添加一个球体,作为左手IK的标记物,命名格式为:武器编号LHTarget。
5.不同的武器要将不同的LHTarget赋值给FullBodyBIipedIK的LeftHandEffector.Target,所以要修改vp_WeaponHandler.cs,在初始化枪械时完成赋值。
首先在代码开头,对该类进行实例化生成对象,
protected FullBodyBipedIK fullBodyBipedIK;
然后在protected virtual void Awake()函数里,将Michael的组件赋值给该对象,
protected virtual void Awake()
{
// store the first player event handler found in the top of our transform hierarchy
m_Player = (vp_PlayerEventHandler)transform.root.GetComponentInChildren(typeof(vp_PlayerEventHandler));
fullBodyBipedIK = transform.root.GetComponentInChildren<FullBodyBipedIK>();
if(Weapons != null)
StartWeapon = Mathf.Clamp(StartWeapon, 0, Weapons.Count);
}
最后在激活枪械函数public void ActivateWeapon(int index)里完成LHTarget的赋值,此处代码要求LHTarget要为枪械的第一个子对象。
public void ActivateWeapon(int index)
{
m_CurrentWeaponIndex = index;
m_CurrentWeapon = null;
if (m_CurrentWeaponIndex > 0)
{
m_CurrentWeapon = Weapons[m_CurrentWeaponIndex - 1];
if (m_CurrentWeapon != null)
m_CurrentWeapon.ActivateGameObject(true);
//Set Left Hand I
if (m_CurrentWeaponIndex != 4 && m_CurrentWeaponIndex != 5) {
Transform LeftHandTarget = m_CurrentWeapon.Weapon3rdPersonModel.transform.GetChild (0);
fullBodyBipedIK.solver.leftHandEffector.target = LeftHandTarget;
fullBodyBipedIK.enabled = true;
} else {
fullBodyBipedIK.enabled = false;
}
}
if(m_CurrentWeapon != null)
m_CurrentShooter = CurrentWeapon.GetComponent<vp_Shooter>();
}