加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Final IK--Interaction System 交互系统

(2016-10-18 14:49:02)
标签:

游戏

分类: unity

Interaction System 交互系统

The Interaction System is designed for the easy setup of full body IK interactions with the dynamic game environment. It requires a character with FullBodyBipedIK and consists of 3 main components: InteractionSystem, InteractionObject and InteractionTarget.

交互系统是专门针对FBBIK(人物骨骼系统)和游戏环境物体互动而设计的,它需要角色上有FBBIK组件,此外还有另外3个重要组件与之相配合使用:Interaction System组件,Interaction ObjectInsteraction Target组件

简单的使用方法:

·   在添加了FBBIK组件的角色上再添加Interaction System组件.

·   在交互物体上添加Interaction Object组件

·   Interaction Object组件上,增加weightCurve组的size,设置 Position Weight曲线的点

    曲线的x轴是时间,Y轴是位置权重值  例如点(0,0)表示,在第零秒,角色的IK动作位置权重为零,即不发生改变  点(0.5,1)表示,0.5秒时,IK动作权重为1,移到交互物体的位置处   点(2,0)表示在第2秒时,角色的IK动作回到原处

·   http://s7/mw690/001KF55Fzy75In62L7866&690IK--Interaction System 交互系统" TITLE="Final IK--Interaction System 交互系统" />


·   在角色上添加InteractionSystemTestGUI组件,设置交互物体,IK的Effector控制器,我这里选择左手选择左手.

·   http://s2/bmiddle/001KF55Fzy75In6HCOB81&690IK--Interaction System 交互系统" />

·   运行场景,点击GUI选项,观察IK动作

·   http://s14/bmiddle/001KF55Fzy75InagCO97d&690IK--Interaction System 交互系统" />

核心API: 

using RootMotion.FinalIK;

 

public InteractionSystem interactionSystem; // 引用角色上的InteractionSystem组件

public InteractionObject button; // 引用要交互的物体上的InteractionObject组件

public bool interrupt; // 如果为真,则交互的动作可以被其他交互动作中止打断

void OnGUI() {

// 开始交互动作

if (GUILayout.Button("Press Button")) {

interactionSystem.StartInteraction(FullBodyBipedEffector.RightHand, button, interrupt);   

 

// 核心API:insteractionSystem.StartInteraction(IK控制器,交互物体,是否可打断);

 

}

}

Final IK插件的demo场景中找到InteractionDemo示例,会有更详细的例子介绍

Interaction System解析

InteractionSystem

http://s2/bmiddle/001KF55Fzy75InddIjL81&690IK--Interaction System 交互系统" />

这个组件应该同样添加在有FBBIK组件的角色上,它驱动和控制角色交互动作.

组件参数:

·   targetTag -  如果不为空,那么只有指定的Tag的物体才能被Interaction system调用(暂时还不知道怎么用)

·   fadeInTime  角色过渡到IK交互动作的时间,值越大,过渡越柔和

·   speed  交互动作的速度倍增值;

·   resetToDefaultsSpeed  当数值大于1,交互动作停止时,回复到默认动作时的速度

·   //以下需要了解Interaction Trigger组件

·   collider  角色身上的collier ,用来记录所有在碰撞范围内的interaction trigger组件

·   camera .角色的第一视角摄像机,在此摄像机的视线范围内看到的interaction trigger物体才有可能有交互动作

·   camRaycastLayers . 可以交互物体的layer

·   camRaycastDistance 摄像机发射射线最远的距离

·   //

·   fullBody 组件角色身上时,会自动引用此FBBIK脚本

·   lookAt - Look At uses a LookAtIK component to automatically turn the body/head/eyes to the Interaction Object.  在发生交互动作时角色会自动注视交互物体;


iK
 引用的角色LookAtIK组件, 
lerpSpeed
 - 注视到交互物体的速度
weightSpeed
 -.  从交互物体转移注视动作的过渡时间

http://s12/bmiddle/001KF55Fzy75InehtPRfb&690

 

InteractionObject

这个组件添加在交互物体上,它控制交互动作的过程, 组件中没有指定交互IK Effector控制器(如左手,左脚)   组件的参数用来控制动作随时间的,位置和旋转轨迹 以及动作过程中触发的事件.

 

   交互物体动画:

交互系统引入动画物体的概念 系统并没有让人物去完成一个开门或按钮的动作,而是通过门开的动作和按钮按下的位移动作来牵引人物骨骼,去完成这个动作.这样交互就会有非常高的自由度 在交互动作发生的同时,你还可以利用interactionObject组件中定义好的OnStartAniamtion,OnTriggerAnimation,OnReleaseAnimationOnEndAnimation事件来播放你想要的人物动画.

组件参数:

·   otherLookAtTarget - the look at target. If null, will look at this GameObject. This only has an effect when the InteractionLookAt component is used. 如果为空,将会看组件所在的物体(这只有InteractionLookAt组件添加后才有用)

·   otherTargetsRoot -. InteracitonTarget组件的根层级物体,这会自动寻找组件所在物体下面的子物体中的interactionTarget组件, 因此所有的interaction Targets组件都应该在其子层级的物体上

·   positionOffsetSpace -交互物体参考那个物体为偏移值,如果空的话,则是以角色物体为参考

·   weightCurves - 权重曲线定义了交互动作的具体过程 曲线的水平线数值从左到代表时间轴从零开始,纵向轴代表位置的权重  :{(0, 0), (1, 1), (2, 0)} 代表了曲线上的三个点,第一个点(0,0)表示时间初始时,权重为0,(1,1)表示第一秒时,位置权重为1,IK动作到了交互物体的所在位置,(2,0)表示第二秒时,权重为零


PositionWeight
 -,IK控制器的位置权重
RotationWeight
 – IK控制器的旋转权重
PositionOffsetX
 - 相对角色正前方向的x轴偏差位移
PositionOffsetY
 - 相对角色正前方向的y轴偏差位移
PositionOffsetZ
 - 相对角色正前方向的z轴偏差位移
Pull
 -, IK控制器的肢体的拉力
Reach
 -, IK控制器的肢体的吸力
RotateBoneWeight
 -旋转骨骼,多数情况下用这个来代替RotationWeight,会有更稳定和平滑的显示效果
Push
 -  IK控制器的肢体的推力
PushParent
 -,  IK控制器的肢体的父物体的推力
PoserWeight
  手或脚的Pose权重,

·   multipliers - Weight curve multipliers针对复用动画曲线,减少重复动画曲线而设计的,如果你需要设置rotationweightpositionweight相同的曲线,你应该这个功能来代替复制一条和positionweight相同的曲线来设置rotationweight, 在这种情况下rotationweight=positonweight*multiplier

·   events - . 事件用来在动作暂停或拾取物体时,触发动画,给脚本发送消息
time
 -开始交互后触发事件的时间
pause
 - 如果打钩,则触发时会停止动作,通过InteractionSystem.ResumeInteraction(FullBodyBipedEffector effectorType) or InteractionSystem.ResumeAll()来使动作继续
pickUp
  打钩,则交互物体被IK控制器拾取,注意只能被一个IK控制器拾取
animations
  播放动画

·   messages  向游戏物体发送消息,功能相当于:GameObject.SendMessage();

http://s5/bmiddle/001KF55Fzy75Infc428c4&690

 

InteractionTarget

如果Interaction Object没有Interaction Targets组件,IK控制器默认的位置和角度就会和interactionObject相同,然而如果你想要固定的交互姿势,(如按钮的手部姿势),你就需要用到interactionTarget组件.

 

实现的方式:

你需要事先复制一个角色的手,摆好姿势,把手放到交互物体(带有interactionObject组件)的子层级下,

在复制的手上添加InteractionTarget组件---interactionObject组件将自动找到它子目录中所有的interactionTargets组件,来矫正IK动作的姿势

http://s5/bmiddle/001KF55Fzy75InfONrS84&690

如何使用Interaction Targets:

·   复制角色,调整交互时的位置,角度和姿势,(最好在运行播放时操作,停止播放前,把调整好的手copy)

·   将复制的调整好姿势的骨骼(:手部)放在交互物体的层级下,删掉角色下没用的物体

·   给复制的手部骨骼添加InteractionTarget组件

·   给角色的手部添加HandPoserGenericPoser组件,这样手就能和复制的手姿势一致

·   运行查看结果

Component variables: 组件参数

·   effectorType - 要控制的IK部位

·   multipliers - 覆盖IK控制器的位置,旋转数值等信息

·   interactionSpeedMlp -更改IK控制器的过渡时间

·   pivot - InteractionTarget的旋转中心(上图中的蓝色圆点),很多情况下角色和交互物体会有一个角度,轴心点可以让角色一致正面面对交互物体

·   twistAxis -. 轴心点旋转的轴向(上图中蓝色的竖线)

·   twistWeight - the weight of twisting the interaction target towards the effector bone in the start of the interaction.

·   swingWeight - the weight of swinging the interaction target towards the effector bone in the start of the interaction. This will make the direction from the pivot to the InteractionTarget match the direction from the pivot to the effector bone.

·   rotateOnce - if true, will twist/swing around the pivot only once at the start of the interaction

http://s12/bmiddle/001KF55Fzy75IngGfqjeb&690

 

InteractionTrigger 

With most Interaction Objects, there is a certain angular and positional range in which they are naturally accessible and reachable to the character. For example, a button can only be pressed with a left hand if the character is within a reasonable range and more or less facing towards it. The Interaction Trigger was specifically designed for the purpose of defining those ranges for each effector and object.

交互物体和角色之间往往有距离和角度上的偏差,比如,一个按钮在角色能触摸到的范围内,只能用左手点击它.

InteractionTrigger根据限定范围来触发符合交互条件IKeffector控制器   比如角色朝向不同时,会智能选择左右两只手选择一只手来打开门

http://s13/bmiddle/001KF55Fzy75InhhSXy6c&690

上图显示了InteractionTrigger为门把手针对左右手定义的不同的交互范围

绿色的球触发碰撞器,记录了角色上的interactionSystem组件

球的体积定义了角色能够和门交互的位置范围

角色正面的朝向如果在紫色范围内,则用右手开门,如果在粉色的区域则用左手开门

使用方法:

·   给角色添加InteractionSystem组件

·   确保角色上有碰撞体和刚体(重要,用来interaction system记录所有可以在触发范围内的interaction trigger组件)

·   新建一个交互物体,附加InteractionObject组件,增加权重曲线,添加位置权重点{(0, 0), (1, 1), (2, 0)}

·   创建一个空游戏物体,命名Trigger,作为交互物体的子物体,,添加InteractionTrigger组件, 并给它添加碰撞器collider组件,确保能够触发interactionSystemOnTriggerEnter方法

·   增加一个Range,增加一个interaction,interactionObject物体赋予红框内.

http://s2/bmiddle/001KF55Fzy75Ini9Z1Te1&690IK--Interaction System 交互系统" />

·   指定effector IK控制器这个选择lefthand

·   设置maxAngle180 这样你就可以在角色任意角度也可以出发Interaction Trigger

·   将以下代码复制到脚本,添加到Interaction trigger组件的游戏物体上:

InteractionSystem 将自动保留角色碰到的所有collider,这个列表能被interactionSystem.triggersInRange访问,那个列表只包括了符合交互条件位置和角度的角色IK控制器

你可以找到离角色最近的trigger:

int closestTriggerIndex = interactionSystem.GetClosestTriggerIndex();

如果closestTriggerIndex值为-1,则没有可用的trigger,如果值不为-1,则可以用一下语句来触发交互

interactionSystem.TriggerInteraction(closestTriggerIndex, false);

Component variables组件参数

·   ranges 可以交互的角色列表, 以及角色触发交互时摄像机位置

·   characterPosition - The range for the character's position and rotation.  角色的位置和角度范围
use
 - 如果不打钩,就不会考虑角色的站的位置和角度,只要接触到collider就触发交互 
offset
 - . 监视角色位置范围的Gizmos在水平位置偏移值
angleOffset
  监视角色 角度范围的偏移值
maxAngle
 -. 限定交互的角度的范围(角色正面方面是否在Gizmos的角度范围内)
radius
 监视角色交互位置的半径. 
orbit
 - if true, will rotate the trigger around it's Y axis relative to the position of the character, so the object can be interacted with from all sides. 如果打钩,则在一个同心圆内的范围

·   http://s11/bmiddle/001KF55Fzy75IniRSwWea&690IK--Interaction System 交互系统" />

http://s8/bmiddle/001KF55Fzy75Injx3Cv27&690

Valid position of the character without 'Orbit'  orbit未勾选,可以交互的范围

http://s5/bmiddle/001KF55Fzy75Inn6gx624&690

Valid positions of the character with 'Orbit'  orbit勾选上,可以交互的范围

·  
fixYAxis
 -.只能在水平方向限定交互的角度

·   cameraPosition - The range for the character camera's position and rotation. 角色的第一视角内看到的物体可以交互
lookAtTarget
 - what the camera should be looking at to trigger the interaction? 目标交互物体
direction
 - the direction from the lookAtTarget towards the camera (in lookAtTarget's space). 观察方向
maxDistance
 - max distance from the lookAtTarget to the camera. 最远限定范围
maxAngle
 - max angle between the direction and the direction towards the camera. 最大角度
fixYAxis
 - fixes the Y axis of the trigger to Vector3.up. This makes the trigger symmetrical relative to the object.限定在水平平面

·   http://s7/bmiddle/001KF55Fzy75InnJ4X406&690IK--Interaction System 交互系统" />

使用cameraPosition 还需要interactionSystem配合使用

http://s12/bmiddle/001KF55Fzy75Inoiivx7b&690IK--Interaction System 交互系统" />

赋予角色的collier, 第一视角的摄像机 选择交互物体所在的Layer, 图中交互物体的layerPlayerLayer

 

http://s10/bmiddle/001KF55Fzy75InoXlIl59&690


 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有