http://blog.csdn.net/myarrow/article/details/44450199

1. 简介

IK与FK对应,正向运动学就是根骨骼带动节点骨骼运动。而反向运动学就是反过来,由子节点带动父节点运动。

2. 实例

对于Humanoid的动画,使用的方法很简单,在Animator窗口中,对于要使用IK的动画状态勾上Foot IK选项,在Base Layer中勾上IK Pass选项。然后在代码中实现OnAnimatorIK函数来控制IK。

其实例代码如下所示(IKCtrl.cs):

[csharp] view
plain
 copy

  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. [RequireComponent(typeof(Animator))]
  5. public class IKCtrl : MonoBehaviour {
  6. protected Animator animator;
  7. public bool isActive = false;
  8. public Transform rightHandObj = null;
  9. private bool isFirst = true;
  10. // Use this for initialization
  11. void Start () {
  12. Debug.Log ("Start is being called");
  13. animator = GetComponent<Animator> ();
  14. }
  15. // a callback for calc IK, when Mecanim run, Animator will call this callback
  16. void OnAnimatorIK(int layerIndex)   {
  17. Debug.Log ("OnAnimatorIK is being called");
  18. if (animator) {
  19. // if the IK is active, set the position and rotation directly to the goal
  20. if(isActive){
  21. // weight =1.0 for the right hand means position and rotation will be at the IK goal(the place the character wants to grab)
  22. animator.SetIKPositionWeight(AvatarIKGoal.RightHand,1.0f);
  23. animator.SetIKRotationWeight(AvatarIKGoal.RightHand,1.0f);
  24. // set the position and the rotation of the rihgt hand where the external object is
  25. if(rightHandObj != null){
  26. Debug.Log ("Set Avatar's position and rotation");
  27. animator.SetIKPosition(AvatarIKGoal.RightHand,rightHandObj.position);
  28. animator.SetIKRotation(AvatarIKGoal.RightHand,rightHandObj.rotation);
  29. }else{
  30. animator.SetIKPositionWeight(AvatarIKGoal.RightHand,0);
  31. animator.SetIKRotationWeight(AvatarIKGoal.RightHand,0);
  32. }
  33. }
  34. }
  35. }
  36. }

3. 动画制作要点

3DS Max中使用IK的情景还是非常多的。比如一个小章鱼,每个脚上面绑上IK,然后就可以通过脚步移动控制整条腿的运动。如果不用IK的话操作起来很麻烦而且不自然。

      而FBX的格式里面也是有IK信息的。只是Unity过滤了相关的数据而已。美术在导出动画之前做这么的操作,然后动画就正常了。

      1) Set up the bone structure as you please.

      2) Create the animations you want, using FK and/or IK

      3) Select all bones and/or IK solvers

      4) Go to Motion->Trajectories and press Collapse. Unity makes a key filter, so the amount of keys you export is irrelevant

      5) "Export" or "Export selected" as newest FBX format

      6) Drop the FBX file into Assets as usual
      在3dmax中ctrl+A选中所有所有骨骼,在右侧的选项卡中选择Motion->Trajectories,如果已经选择好骨骼,Collapse按钮就可以正常点击,点击这个按钮,然后正常的导出动画。这样Unity中的动画表现就跟3dmax一致了。

注意,使用Collapse功能会修改动画的帧(使帧间隔变得一样),这样我们很多动作播放的时候就会被改变,比如攻击动作会变得很慢,没有力度。美术应该在Collapse后再次修改动画(或者是在制作动画之前使用Collapse)以保证动画的正确性。

参考:http://blog.csdn.net/langresser_king/article/details/22725499

最新文章

  1. webservice 实现json模式
  2. js实现简单的滑动门和tab选项卡
  3. List&lt;string&gt;里 每个元素重复了多少次
  4. 解决error C2011: &#39;fd_set&#39; : &#39;struct&#39; type redefinition的方法
  5. (右偏树)Bzoj2333: [SCOI2011]棘手的操作
  6. LeetCode之“数组”:Rotate Array
  7. MFC自绘菜单
  8. Eclipse导入maven项目时,pom-xml文件报错处理方法
  9. linux系统执行mysql脚本:Can&#39;t connect to local MySQL server through socket &#39;/tmp/mysql.sock&#39;
  10. VS IISExpress REST DELETE 405 Method Not Allowed
  11. 如何修改config?
  12. Django学习---笔记一
  13. SharePoint 2013 Workflow Manager 1.0 卸载
  14. 超实用!!!使用IDEA插件Alibaba Cloud Toolkit工具一键部署本地应用到ECS服务器
  15. 20165305 苏振龙《Java程序设计》第六周学习总结
  16. day 55 jQuery 之事件 绑定等
  17. 一个基于DPI技术实现了内网资产识别的应用
  18. DISTINCT 与 GROUP BY 的比较
  19. Linux 文件IO管理 - POSIX
  20. 【PAT】1024. Palindromic Number (25)

热门文章

  1. Mysql 存储过程使用游标
  2. 学习某些API的方法
  3. 多用GCD,少用performSelect系列方法
  4. 九度OJ 1103:二次方程计算器 (解方程)
  5. 记录一次MySQL两千万数据的大表优化解决过程,提供三种解决方案(转)
  6. PAT天梯赛 L2-026. 小字辈 【BFS】
  7. shared SDK 微信开放平台遇到的问题
  8. poj 3617 Best Cow Line 解题报告
  9. Java(一)——认识Java语言
  10. hdu-5762 Teacher Bo(抽屉原理+暴力)