<划重点的Unity2017> 人物相关的物理系统组件详述
继续上一篇对物理系统的概述。本篇主要学习和物理系统相关联的一些组件。这里略去了一些无聊的碰撞体,直接从一些平时注意不到但是很有意思的组件开始。
首先介绍一个基础概念:力矩在物理学里是指作用力使物体绕着转动轴或支点转动的趋向。
(1)Character Joint
Character Joints are mainly used for Ragdoll effects. They are an extended ball-socket joint which allows you to limit the joint on each axis.
角色关节在布娃娃系统当中应用。主要就是根据骨骼将整个人物的碰撞体以及骨骼之间限制角度等等调整好,从而在没有动作的情况下,模拟出真实的人物死亡或者炸飞的效果。
该控件的几个重要属性:
The point in the GameObject’s local space where the joint rotates around.
Anchor:锚点,整个绕着该锚点进行旋转。注意这是局部坐标系。
Auto Configure Connected Anchor:自动设置链接锚点的Flag。如果设置为true,那么链接锚点(Connected Anchor)会自动进行计算。
Connected Anchor:Manual configuration of the connected anchor position.
这个是手动调整锚点的位置。这个相对于锚点,是全局坐标。调整位置可以让骨骼更自然。比如slenderman的游戏角色。
The Swing 1 Limit: limits the rotation around the swing axis (visualized with the green axis on the gizmo). The limit angle is symmetric. Thus a value of 30 will limit the rotation between –30 and 30.
限制围绕摆动轴(swing axis)的旋转。限制角度是对称的。
The Swing 2 Limit: axis isn’t visualized on the gizmo but the axis is orthogonal to the two other axes (that is the twist axis visualised in orange on the gizmo and the Swing 1 Limit visualised in green on the gizmo). The angle is symmetric, thus a value of 40 will limit the rotation around that axis between –40 and 40 degrees.
在Gizmo上轴不可视化,但轴与其他两个轴正交。该角度是对称的,因此值40将限制该轴在-40度和40度之间的旋转。
Low Twist Limit :限制关节的下限。
High Twist Limit:限制关节的上限。
Break Force :The force that needs to be applied for this joint to break.
关节脱落所需要的力,如果要做断肢的效果,必不可少。
Break Torque:The torque that needs to be applied for this joint to break.
关节脱落所需要的力矩。
以上两个属性一旦满足,当前骨骼不受到character joint的影响。
Enable Collision:When checked, this enables collisions between bodies connected with a joint.
是否开启碰撞。当该Flag为True的时候,同一个身体之间的碰撞体会互相作用。
注意在上述部分属性当中还有一些子属性:
Bounciness: A value of 0 will not bounce. A value of 1 will bounce without any loss of energy.
反弹力。value为1的值会不收任何能量损失的反弹。
Spring: The spring force used to keep the two objects together.
弹簧力。当两物体相作用的时候会体现。
Damper: The damper force used to dampen the spring force.
阻尼:使用阻尼来阻碍弹簧力。
Contact Distance Within the contact distance from the limit contacts will persist in order to avoid jitter.
恒定力:在constact distance属性范围内都会持续,这将避免抖动。
布娃娃系统
在了解以上的功能基础上,我们来了解布娃娃系统。基于character joint的自动生成系统。
GameObject > 3D Object > Ragdoll就可以打开布娃娃系统制作。
将你的模型拖到视图当中之后,将其骨骼拖入到对应布娃娃系统面板的对应位置,点击create,你就会发现你的模型相应的骨骼都已经创建好了相应的刚体、碰撞体和角色关节。
你可能会疑惑创造一个跟玩偶一样的东西有屁用。下面我说几个例子:
死亡空间2 其中抖动的变异体大家如果玩过一定印象深刻。调整他的 archor故意让其抖动。
上古卷轴5 当主角被巨人一棒子打飞的时候,角色处于骨骼的随机状态。来模拟非常真实的被击飞效果。
轩辕剑 其中角色的死亡动画就是用布娃娃系统制作。通过布娃娃系统,我们可以模拟真实的角色受力形态,而不是仅仅播放死亡动画。
(2)Constant Force 恒定力
Constant Force is a quick utility for adding constant forces to a Rigidbody. This works great for one shot objects like rockets, if you don’t want it to start with a large velocity but instead accelerate.
恒定力是通过针对刚体进行力的增加的一个非常优秀的组件。
例如模拟火箭的升空。很多小游戏可以通过这个组件模拟出真实的物理特效。
下面介绍该组件相关的属性:
Force:The vector of a force to be applied in world space.
应用于世界坐标系当中的力。
Relative Force The vector of a force to be applied in the object’s local space.
应用于局部坐标系的力。
Torque The vector of a torque, applied in world space. The object will begin spinning around this vector. The longer the vector is, the faster the rotation.
力矩:这个力矩应用于世界坐标系。根据不同的轴进行旋转。长度越长转的越快。
Relative Torque The vector of a torque, applied in local space. The object will begin spinning around this vector. The longer the vector is, the faster the rotation.
相对力矩:这个力矩相对于局部坐标系。
(2)布料系统 Cloth
The Cloth component provides a physics-based solution for the simulation of fabrics and works in conjunction with the Skinned Mesh Renderer. While it has been specifically designed for character clothing it is still possible to use arbitrary, non-skinned meshes.
布料组件应用于基于物理的纤维模拟,当然需要配合Skinned Mesh Render组件的配合。尤其是针对Character进行设计的衣服。当然也可以为非角色的object使用。
Stretching Stiffness:Stretching stiffness of the cloth.
拉伸刚度:衣服的拉伸刚度。
Bending Stiffness Bending stiffness of the cloth.
弯曲刚度:衣服的弯曲刚度。
Use Tethers Apply constraints that help to prevent the moving cloth particles from going too far away from the fixed ones. This helps to reduce excess stretchiness.
使用
Use Gravity :Should gravitational acceleration be applied to the cloth?
使用重力:让衣服具有重力质感。
Damping:Motion damping coefficient.
阻尼运动。
External Acceleration:A constant, external acceleration applied to the cloth.
额外的加速度:施加到衣服上的额外加速度。比如风吹的效果。
Random Acceleration:A random, external acceleration applied to the cloth.
随机的加速度:施加到衣服上随机的加速度。
World Velocity Scale How much world-space movement of the character will affect cloth vertices.
世界速度Scale:人物的移动会作用于角色上。
World Acceleration Scale How much world-space acceleration of the character will affect cloth vertices.
世界加速度Scale:世界的加速度会作用于衣服上。
Friction The friction of the cloth when colliding with the character.
与人物碰撞时,布料的摩擦力。
Collision Mass Scale How much to increase mass of colliding particles.
碰撞质量。
Use Continuous Collision Enable continuous collision to improve collision stability.
多次碰撞:通过多次碰撞来增加碰撞稳定性。
Use Virtual Particles Add one virtual particle per triangle to improve collision stability.
使用虚拟粒子:每一个三角形都设置一个虚拟粒子,来提升碰撞稳定性。
Solver Frequency Number of solver iterations per second.
解释器速度:每秒所需要解释的次数。这里理解为计算的次数吧。
Sleep Threshold Cloth’s sleep threshold.
睡眠阈值。
Capsule Colliders An array of CapsuleColliders which this Cloth instance should collide with.
胶囊碰撞体:衣服所作用于的胶囊碰撞体。
Sphere Colliders An array of ClothSphereColliderPairs which this Cloth instance should collide with.
球状碰撞体:大体如上。
Edit Constraints Tool 编辑约束模式
Selecting Edit Constraints will enter the editor into a mode to edit the constraints applied to each of the vertices in the cloth mesh. All vertices will be coloured based on the current Visualization mode to display the difference between their respective values.
在Cloth组件下可以进入编辑约束模式,从而编辑应用到每一个衣服的点的状况。可以在可视化情况下对每个点进行颜色修改,从而影响不同点之间的作用情况。
Property: Function:
Visualization Changes the visual appearance of the tool in the Scene view between Max Distance and Surface Penetration Values. A toggle for Manipulate Backfaces is also available.
可以在最大距离和表面渗透之间的场景当中更改工具的视觉外观。
Max Distance The maximum distance a cloth particle can travel from its vertex position.
最大距离:衣服粒子距离其顶点位置的最远距离。
Surface Penetration How deep the cloth particle can penetrate the mesh.
表面渗透:布粒子可以穿透网格有多深。
关于编辑器的使用有两种方式:
There are two modes that can be used for changing the values for each vertex, in Select mode a group of vertices can be selected using the mouse cursor to either draw a selection box or else by individually clicking on vertices one at a time. Once any number of cloth vertices have been selected they can then have either Max Distance or Surface Penetration constraints enabled and a value assigned.
一种select方式,就像玩RTS一样拖出一堆粒子,之后可以就可以对其的最大距离和表面渗透进行修改。
Paint mode allows you to directly adjust each individual vertex by clicking on it, again with options to adjust the Max Distance, Surface Penetration, or both. As before a value can be assigned and the visual representation in the scene view will be updated.
另外一种是绘制模式,发挥你的艺术天分吧。
Cloth is unable to simply collide with arbitrary world geometry, and now will only interact with the colliders specified in either the Capsule Colliders or Sphere Colliders arrays.
衣服组件是对世界当中的碰撞和几何体无效的。并且不可以被除了胶囊和球碰撞体所影响。
The sphere colliders array can contain either a single valid SphereCollider instance (with the second one being null), or a pair. In the former cases the ClothSphereColliderPair just represents a single sphere collider for the cloth to collide against. In the latter case, it represents a conic capsule shape defined by the two spheres, and the cone connecting the two. Conic capsule shapes are useful for modelling limbs of a character.
球体球体碰撞体数组可以包含单个球体碰撞体实例。只需要将对应的胶囊体和球体放到对应的list当中就会对布料有所影响。
这里的名词:ClothSphereColliderPair 更多的是一种类似于锥形的胶囊体。用于模拟肢体。
下面附上我的一个小例子:
正如上图所示,我对小姐姐的骨骼碰撞体并没有仔细的调整。大体添加了五个胶囊碰撞体。小姐姐的衣服会根据小姐姐的动作做出非常逼真的物理动作…当然如果你把小姐姐的衣服的点都绘制成绿色(max distance很大)就会出现爆衣特效…为了和谐,这里不放图了。大家可以上网找一些素材试试。蛮有意思的组件。有哪些地方有问题欢迎大家及时提出。