Unity IK(反向运动学)初探
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):
- using UnityEngine;
- using System.Collections;
- using System;
- [RequireComponent(typeof(Animator))]
- public class IKCtrl : MonoBehaviour {
- protected Animator animator;
- public bool isActive = false;
- public Transform rightHandObj = null;
- private bool isFirst = true;
- // Use this for initialization
- void Start () {
- Debug.Log ("Start is being called");
- animator = GetComponent<Animator> ();
- }
- // a callback for calc IK, when Mecanim run, Animator will call this callback
- void OnAnimatorIK(int layerIndex) {
- Debug.Log ("OnAnimatorIK is being called");
- if (animator) {
- // if the IK is active, set the position and rotation directly to the goal
- if(isActive){
- // weight =1.0 for the right hand means position and rotation will be at the IK goal(the place the character wants to grab)
- animator.SetIKPositionWeight(AvatarIKGoal.RightHand,1.0f);
- animator.SetIKRotationWeight(AvatarIKGoal.RightHand,1.0f);
- // set the position and the rotation of the rihgt hand where the external object is
- if(rightHandObj != null){
- Debug.Log ("Set Avatar's position and rotation");
- animator.SetIKPosition(AvatarIKGoal.RightHand,rightHandObj.position);
- animator.SetIKRotation(AvatarIKGoal.RightHand,rightHandObj.rotation);
- }else{
- animator.SetIKPositionWeight(AvatarIKGoal.RightHand,0);
- animator.SetIKRotationWeight(AvatarIKGoal.RightHand,0);
- }
- }
- }
- }
- }
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
Unity IK(反向运动学)初探的更多相关文章
- 【Unity Shaders】初探Surface Shader背后的机制
转载请注明出处:http://blog.csdn.net/candycat1992/article/details/39994049 写在前面 一直以来,Unity Surface Shader背后的 ...
- Unity 摄像机旋转初探
接触打飞机的游戏时都会碰见把摄像机绕 x 轴顺时针旋转 90°形成俯瞰的视角的去看飞船.也没有多想,就感觉是坐标系绕 x 轴旋转 90°完事了.但是昨天用手比划发一下发现不对.我就想这样的话绕 x 轴 ...
- 分享一个大神自己的blog
std::sort() 详解 http://feihu.me/blog/ C++11 新特性 http://blog.guoyb.com/2016/09/19/cpp11-all/ unity3d 相 ...
- Unity给力插件之Final IK
Final IK细节: 1.Aim IK:设定一个目标,关节末端始终朝向该目标,一般用来做头部的朝向. 步骤: a.在模型头节点处添加Aim空物体并reset b.给模型添加Aim IK组件,并填上A ...
- AnimatorController反向运动学IK
通过使用反向运动学IK,我们可以根据需要控制角色身体某个特定部位进行旋转或移动,达到想要的一些效果,比如:在移动时,让一只脚带伤拖行:让手抬起去拿桌上的苹果:让脑袋一直面向我们的色像机,就像一直注视着 ...
- 基于Unity的AR开发初探:第一个AR应用程序
记得2014年曾经写过一个Unity3D的游戏开发初探系列,收获了很多好评和鼓励,不过自那之后再也没有用过Unity,因为没有相关的需求让我能用到.目前公司有一个App开发的需求,想要融合一下AR到A ...
- unity初探之黑暗之光(2)
unity初探之黑暗之光(2) 一.设置角色跟随鼠标点击移动 思路:使用charactercollider的SimpleMove方法来控制角色的移动.通过摄像机的射线投射到地面,通过屏幕上的一个点也就 ...
- Unity初探之黑暗之光(1)
Unity初探之黑暗之光(1) 1.镜头拉近 public float speed=10f;//镜头的移动速度 ;//镜头的结束位置 // Update is called once per fram ...
- Unity初探—SpaceShoot
Unity初探—SpaceShoot DestroyByBoundary脚本(C#) 在游戏中我们添加了一个Cube正方体,让他来作为游戏的边界.它是可以触发触发事件的(勾选Is Trigger),当 ...
随机推荐
- MongoDB复制集架构搭建
创建目录 mkdir -p /data/r0 /data/r1 /data/r2 声明实例 ./bin/mongod --port 27017 --dbpath /home/workspace/dat ...
- appium()-The event firing
原文地址:https://github.com/appium/java-client/blob/master/docs/The-event_firing.md since 4.1.0 The purp ...
- Handler向子线程发送数据
public class MainActivity extends AppCompatActivity { private static final String TAG = "MainAc ...
- linux内核驱动中对文件的读写 【转】
本文转载自:http://blog.chinaunix.net/uid-13059007-id-5766941.html 有时候需要在Linux kernel--大多是在需要调试的驱动程序--中读写文 ...
- underscore.js中模板函数应用
一.使用技术要点 (1)使用zepto.js的ajax请求; (2)使用underscore.js的_.template设定模板,模板一般以<script type="text/tem ...
- 【应用】图片翻转js
图片翻转:图片随着鼠标指针划过进行替换 <img src="example.gif" onmouseover="this.src='exampleTwo.gif'& ...
- Java笔记(四)
13. 集合框架: 集合中存储的都是对象的引用(地址) 迭代器:集合的取出元素的方式 import java.util.ArrayList; import java.util.Iterator; pu ...
- bzoj 2006 [NOI2010]超级钢琴——ST表+堆
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2006 每个右端点的左端点在一个区间内:用堆记录端点位置.可选区间,按价值排序:拿出一个后也许 ...
- 5.js屏蔽方向键,兼容IE和firefox
document.onkeydown=function(e){ e=e||event; //屏蔽向左的方向键 if(e.keyCode==37){ alert('禁止向左的方向键!'); return ...
- asp.net中FileUpload得到上传文件的完整路径
asp.net中FileUpload得到上传文件的完整路径 Response.Write("完整路径:" + Server.MapPath(FileUpload1.PostedFi ...
