标题: [Unity 组件参考手册]组件:物理组件之刚体 [打印本页] 作者: . 时间: 2013-1-29 17:24 标题: [Unity 组件参考手册]组件:物理组件之刚体 Rigidbodies enable your GameObjects to act under the control of physics. The Rigidbody can receive forces and torque to make your objects move in a realistic way. Any GameObject must contain a Rigidbody to be influenced by gravity, act under added forces via scripting, or interact with other objects through the NVIDIA PhysX physics engine.刚体使物体能在物理控制下运动。刚体可通过接受力与扭矩,使物体像现实方式一样运动。任何物体想要受重力影响,受脚本施加的力的作用,或通过NVIDIA PhysX物理引擎来与其他物体交互,都必须包含一个刚体组件。
Rigidbodies allow GameObjects to act under physical influence
刚体让物体在物理影响下运动。
[Properties 属性]---------------------------------------------------------------------------------Mass 质量
The mass of the object (arbitrary units). It is recommended to make masses not more or less than 100 times that of other Rigidbodies.
物体的质量(任意单位)。建议一个物体的质量不要多于或少于其他单位的100倍。
Drag 阻力
How much air resistance affects the object when moving from forces. 0 means no air resistance, and infinity makes the object stop moving immediately.
当受力移动时物体受到的空气阻力。0表示没有空气阻力,极大时使物体立即停止运动。
Angular Drag 角阻力
How much air resistance affects the object when rotating from torque. 0 means no air resistance, and infinity makes the object stop rotating immediately.
当受扭力旋转时物体受到的空气阻力。0表示没有空气阻力,极大时使物体立即停止旋转。
Use Gravity 使用重力
If enabled, the object is affected by gravity.
若激活,则物体受重力影响。
Is Kinematic 是否是运动学
If enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform. This is useful for moving platforms or if you want to animate a Rigidbody that has a HingeJoint attached.
若激活,该物体不再受物理引擎驱动,而只能通过变换来操作。适用于模拟运动的平台或者模拟受铰链关节连接的刚体。
Interpolate 插值
Try one of the options only if you are seeing jerkiness in your Rigidbody's movement.
当你发现刚体运动时抖动,可以尝试下面的选项。
None 无
No Interpolation is applied. 不应用插值。
Interpolate 内插值
Transform is smoothed based on the Transform of the previous frame.
基于上一帧的变换来平滑本帧变换。
Extrapolate 外插值
Transform is smoothed based on the estimated Transform of the next frame.
基于下一帧的预估变换来平滑本帧变换。
Freeze Rotation 冻结旋转
If enabled, this GameObject will never rotate based on collisions or forces added via script -- it will only rotate when using transform.Rotate().
若激活,物体将不会受碰撞或脚本施加的力而旋转——只能调用transform.Rotate()来旋转。
Collision Detection 碰撞检测
Used to prevent fast moving objects from passing through other objects without detecting collisions.
碰撞检测模式。用于避免高速物体穿过其他物体,却未触发碰撞。
Discrete 离散
Use Discreet collision detection against all other colliders in the scene. Other colliders will use Discreet collision detection when testing for collision against it. Used for normal collisions (This is the default value).
离散碰撞检测。使用离散碰撞检测模式来与场景中其他碰撞器进行碰撞检测。其他物体与它的碰撞检测,也会应用这种模式。适用于普通碰撞(这是默认的模式)。
Continuous 连续
Use Discrete collision detection against dynamic colliders (with a rigidbody) and continuous collision detection against static MeshColliders (without a rigidbody). Rigidbodies set to Continuous Dynamic will use continuous collision detection when testing for collision against this rigidbody. Other rigidbodies will use Discreet Collision detection. Used for objects which the Continuous Dynamic detection needs to collide with. (This has a big impact on physics performance, leave it set to Discrete, if you don't have issues with collisions of fast objects)
连续碰撞检测。使用离散碰撞检测来检测与动态碰撞器(刚体)的碰撞,使用连续碰撞检测来检测与静态网格(非刚体)的碰撞检测。采用连续动态碰撞检测模式的刚体碰见这类物体也将采用连续碰撞检测模式。而与其他刚体将采用离散碰撞检测模式。这种模式适用于那些采用动态连续碰撞模式的物体碰撞的物体。(这对物理表现有很大的影响,如果你不关心与高速物体的碰撞,那么就让其为默认的离散模式。)
Continuous Dynamic 动态连续
Use continuous collision detection against objects set to Continuous and Continuous Dynamic Collision. It will also use continuous collision detection against static MeshColliders (without a rigidbody). For all other colliders it uses discreet collision detection. Used for fast moving objects.
连续动态碰撞检测。使用连续动态碰撞检测模式来检测与连续模式和连续动态模式的物体间的碰撞。也适用于与静态网格(非刚体)的碰撞检测。而与之碰撞的其他模式的物体,采用的是离散动态碰撞检测模式。适用于高速物体。
Constraints 约束
Restrictions on the Rigidbody's motion:-
对刚体运动的约束。
Freeze Position 冻结位置
Stops the Rigidbody moving in the world X, Y and Z axes selectively.
刚体在世界中沿所选X,Y,Z轴的移动,将无效。
Freeze Rotation 冻结旋转
Stops the Rigidbody rotating around the world X, Y and Z axes selectively.
刚体在世界中沿所选的X,Y,Z轴的旋转,将无效。 [Details 细节]Rigidbodies allow your GameObjects to act under control of the physics engine. This opens the gateway to realistic collisions, varied types of joints, and other very cool behaviors. Manipulating your GameObjects by adding forces to a Rigidbody creates a very different feel and look than adjusting the Transform Component directly. Generally, you shouldn't manipulate the Rigidbody and the Transform of the same GameObject - only one or the other.刚体让物体在物理引擎控制下运动。它可以通过真实碰撞来开门,实现各种类型的关节及其他很酷的行为。通过力来操纵物体,与直接通过变换不同,有一种不同的感觉。通常情况下,对同一物体,要么通过刚体操纵,要么通过变换操纵。The biggest difference between manipulating the Transform versus the Rigidbody is the use of forces. Rigidbodies can receive forces and torque, but Transforms cannot. Transforms can be translated and rotated, but this is not the same as using physics. You'll notice the distinct difference when you try it for yourself. Adding forces/torque to the Rigidbody will actually change the object's position and rotation of the Transform component. This is why you should only be using one or the other. Changing the Transform while using physics could cause problems with collisions and other calculations.通过变换与通过刚体操纵最大的不同在于使用了力。刚体相比于变换,能够接受力与扭力。变换能够控制平移和旋转,但与物理方式的实现不同。你可以通过实践来明显地区分它们的不同。给刚体施加力和力矩实际也会改变物体变换组件的位置与旋转角度。这就是为什么在变换和刚体间,最好只选择一种操纵方式的原因。同时使用两种方式会导致旋转及其他计算出现问题。Rigidbodies must be explicitly added to your GameObject before they will be affected by the physics engine. You can add a Rigidbody to your selected object from Components->hysics->Rigidbody in the menubar. Now your object is physics-ready; it will fall under gravity and can receive forces via scripting, but you may need to add a Collider or a Joint to get it to behave exactly how you want.刚体在受物理引擎影响之前,必须明确添加给物体。你可以通过选中物体,然后在菜单Components->hysics->Rigidbody来增加一个刚体组件。现在,你的物体的物理属性就设置好了,但你也可以根据需要来为其增加碰撞器或关节。
Parenting 父子级When an object is under physics control, it moves semi-independently of the way its transform parents move. If you move any parents, they will pull the Rigidbody child along with them. However, the Rigidbodies will still fall down due to gravity and react to collision events.当一个物体处于物理控制中,他会以半独立的方式随着变换的父亲的移动而移动。如果你移动父物体,那么它会将子刚体拖向它。但是,这个刚体仍然会根据重力下落或进行碰撞反应。
Scripting 脚本To control your Rigidbodies, you will primarily use scripts to add forces or torque. You do this by calling AddForce() and AddTorque() on the object's Rigidbody. Remember that you shouldn't be directly altering the object's Transform when you are using physics.可以通过脚本增加力或力矩来控制你的刚体。通过调用刚体中的AddForce()和AddTorque方法。 记住,不要同时使用物理与变换。
Animation 动画For some situations, mainly creating ragdoll effects, it is neccessary to switch control of the object between animations and physics. For this purpose Rigidbodies can be marked isKinematic. While the Rigidbody is marked isKinematic, it will not be affected by collisions, forces, or any other part of physX. This means that you will have to control the object by manipulating the Transform component directly. Kinematic Rigidbodies will affect other objects, but they themselves will not be affected by physics. For example, Joints which are attached to Kinematic objects will constrain any other Rigidbodies attached to them and Kinematic Rigidbodies will affect other Rigidbodies through collisions.有些情况下,比如想实现布娃娃效果。需要刚体在动画与物理的操纵方式间切换。这种情况下,刚体可以标记为运动学模式。当刚体标记为运动学模式,他不会受到碰撞,力及任何物理影响,它表示你必须直接通过变换的方式来操纵该物体。运动学模式的刚体会与其他物体进行物理交互,但自身不受物理影响。例如,通过关节约束那些和运动学刚体连接起来的刚体,运动学刚体影响那些与之发生碰撞的刚体。
Colliders 碰撞器Colliders are another kind of component that must be added alongside the Rigidbody in order to allow collisions to occur. If two Rigidbodies bump into each other, the physics engine will not calculate a collision unless both objects also have a Collider attached. Collider-less Rigidbodies will simply pass through each other during physics simulation.碰撞器是另一种组件,它和刚体一起,来使碰撞发生。如果两个刚体撞在一起,物理引擎将不会计算碰撞除非它们包含一个碰撞器组件。没有碰撞器的刚体,会在物理模拟中相互穿透。
Colliders define the physical boundaries of a Rigidbody 碰撞器定义刚体的物理边界。Add a Collider with the Component->hysics menu. View the Component Reference page of any individual Collider for more specific information:通过菜单Component->hysics menu来添加一个碰撞器。想知道更多信息,请看参考手册中碰撞器方面的介绍。 Box Collider - primitive shape of a cube
盒碰撞器——基本形状是个盒子。
Sphere Collider - primitive shape of a sphere
球碰撞器——基本形状是个球。
Capsule Collider - primitive shape of a capsule
胶囊碰撞器——基本形状是个胶囊。
Mesh Collider - creates a collider from the object's mesh, cannot collide with another Mesh Collider
网格碰撞器——从物体的网格创建一个碰撞器。不能与其他网格碰撞器相碰撞。
Wheel Collider - specifically for creating cars or other moving vehicles
轮碰撞器——特殊的碰撞器,用于创建车或其他移动交通工具。 Compound Colliders 复合碰撞器Compound Colliders are combinations of primitive Colliders, collectively acting as a single Collider. They come in handy when you have a complex mesh to use in collisions but cannot use a Mesh Collider. To create a Compound Collider, create child objects of your colliding object, then add a primitive Collider to each child object. This allows you to position, rotate, and scale each Collider easily and independently of one another.组合碰撞器是基本碰撞器的组合,共同扮演一个碰撞器的角色。当你有一个复杂网格却不适用网格碰撞器的情况下,使用组合碰撞器是个好的选择。要创建组合碰撞器,先为你的碰撞物体创建子对象,然后对每个子对象创建一个基本碰撞器。这样就允许你轻易的独立移动、旋转和放缩每个碰撞器。
A real-world Compound Collider setup 一个真实的组合碰撞器的配置In the above picture, the environment has a Mesh Collider attached. Mesh Colliders work the best for terrain or environments made from irregular shapes. The gun_model GameObject has a Rigidbody attached, and multiple primitive Colliders as child GameObjects. When the Rigidbody parent is moved around by forces, the child Colliders move along with it. The primitive Colliders will collide with the environment's Mesh Collider, and the parent Rigidbody will alter the way it moves based on forces being applied to it and how its child Colliders interact with other Colliders in the Scene.上图中,环境里包含一个网格碰撞器。网格碰撞器的最佳适用地方是不规则形状的地形或环境。如图,枪模型物体包含一个刚体组件,以及数个基本碰撞器的子物体。当刚体这个父对象受力移动时,它的子碰撞器也跟着移动。基本碰撞器与环境的网格碰撞器发生碰撞时,父对象的刚体也会因其子碰撞器与环境中其他碰撞器发生碰撞产生的力而改变运动轨迹 。Mesh Colliders can't normally collide with each other. If a Mesh Collider is marked as Convex, then it can collide with another Mesh Collider. The typical solution is to use primitive Colliders for any objects that move, and Mesh Colliders for static background objects.网格碰撞器之间通常不相互碰撞,但如果一个网格碰撞器被标记为凸体,那么它就可以与其他网格碰撞器碰撞。典型的解决方案是,对移动的对象使用基本碰撞器,而对静态环境对象使用网格碰撞器。
Continuous Collision Detection 连续碰撞检测Continuous collision detection is a feature to prevent fast-moving colliders from passing each other. This may happen when using normal (Discrete) collision detection, when an object is one side of a collider in one frame, and already passed the collider in the next frame. To solve this, you can enable continuous collision detection on the rigidbody of the fast-moving object. Set the collision detection mode to Continuous to prevent the rigidbody from passing through any static (ie, non-rigidbody) MeshColliders. Set it to Continuous Dynamic to also prevent the rigidbody from passing through any other supported rigidbodies with collision detection mode set to Continuous or Continuous Dynamic. Continuous collision detection is supported for Box-, Sphere- and CapsuleColliders. Note that continuous collision detection is intended as a safety net to catch collisions in cases where objects would otherwise pass through each other, but will not deliver physically accurate collision results, so you might still consider decreasing the fixed Time step value in the TimeManager inspector to make the simulation more precise, if you ***n into problems with fast moving objects.连续碰撞检测的主要作用是避免高速物体的穿透。在离散碰撞检测模式下,一个高速物体的上一帧位置在一个碰撞器的一边,而下一帧位置就穿透该碰撞器时,就发生了穿透。为了解决这个问题,你要为高速物体设置连续碰撞检测模式。设置连续碰撞检测模式将避免刚体穿透静态网格碰撞器(该网格未必是刚体)。而设置为连续动态碰撞检测将避免刚体穿透设为连续动态碰撞检测与动态碰撞检测的刚体。盒碰撞器、球碰撞器技胶囊碰撞器支持动态碰撞检测。主要,连续碰撞检测只是提供了一种穿透的保护,它保证捕获碰撞事件,但并不保证碰撞反应的精确性。所以,当你发现高速物体有这方面问题时,得考虑降低TimeManager中的固定时间间隔来让模拟更加的精确。
Use the right size 使用正确的大小The size of the your GameObject's mesh is much more important than the mass of the Rigidbody. If you find that your Rigidbody is not behaving exactly how you expect - it moves slowly, floats, or doesn't collide correctly - consider adjusting the scale of your mesh asset. Unity's default unit scale is 1 unit = 1 meter, so the scale of your imported mesh is maintained, and applied to physics calculations. For example, a ***mbling skyscraper is going to fall apart very differently than a tower made of toy blocks, so objects of different sizes should be modeled to accurate scale.你的物体网格的大小要比刚体的质量更加重要。如果你发现你的刚体不像你所期望的那样运动——慢、飘、碰撞不正确——那么请考虑调整你的网格资源的大小。Unity的默认长度单位是1单位=1米。你导入模型的大小会被保持,并参与物理运算中。例如,一个摩天大楼倒塌的表现肯定要异于一个玩具积木搭起来的塔,所以,对不同大小物体,要用精确的比例建模。If you are modeling a human make sure he is around 2 meters tall in Unity. To check if your object has the right size compare it to the default cube. You can create a cube using GameObject->Create Other->Cube. The cube's height will be exactly 1 meter, so your human should be twice as tall.如果对一个人体建模,那么保证它大概在Unity中2米高。可以和一个默认的盒子对比来判断大小。使用 GameObject->Create Other->Cube来创建盒子。盒子的高为1米,所以你的人高度应该是它的两倍。If you aren't able to adjust the mesh itself, you can change the uniform scale of a particular mesh asset by selecting it in Project View and choosing Assets->Import Settings... from the menubar. Here, you can change the scale and re-import your mesh.如果你不能自己调整网格,那你可以修改一个指定网格资源的比例,通过在项目视图中选中它,然后在目录里选择Assets->Import Settings,在这里,你可以选择比例,然后重新加载你的网格。If your game requires that your GameObject needs to be instantiated at different scales, it is okay to adjust the values of your Transform's scale axes. The downside is that the physics simulation must do more work at the time the object is instantiated, and could cause a performance drop in your game. This isn't a terrible loss, but it is not as efficient as finalizing your scale with the other two options. Also keep in mind that non-uniform scales can create undesirable behaviors when Parenting is used. For these reasons it is always optimal to create your object at the correct scale in your modeling application.如果物体在游戏中需要实例化成不同的比例,可以调整变换组件的比例轴。这种做法的缺点是在物体实例化时,物理模拟将执行更多操作,会导致游戏性能下降。 这不是很可怕的下降,但确实没有采用其他两种方法那样有效率。此外,父对象使用一个非标准比例的物体也会产生不好的行为。所以,建议是创建物体时尽量调整好标准比例。
[Hints 提示] The relative Mass of two Rigidbodies determines how they react when they collide with each other.
两个物体的相对质量定义它们之间的碰撞反应表现。
Making one Rigidbody have greater Mass than another does not make it fall faster in free fall. Use Drag for that.
一个质量大的物体并不会在自由落体中下落更快。想实现这种现象请使用阻力。
A low Drag value makes an object seem heavy. A high one makes it seem light. Typical values for Drag are between .001 (solid block of metal) and 10 (feather).
阻力越大,物体看起来越轻,阻力越小,物体看起来越重。阻力的典型值在0.001(砖头)到10(羽毛)之间。
If you are directly manipulating the Transform component of your object but still want physics, attach a Rigidbody and make it Kinematic.
如你直接操纵一个物体的变换同时又想拥有物理特性,那么 为其增加一个刚体组件,并将其设为运动学模式。
If you are moving a GameObject through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.
若你通过变换来移动一个物体,并想接受碰撞或触发消息 ,你必须为其在移动时附加一个刚体组件。 【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/