Physics 物理

Date:2011-10-15

Unity has NVIDIA PhysX physics engine built-in. This allows for unique emergent behaviour and is generally very cool.

Unity内置NVIDIA PhysX物理引擎。这用来做独特的突发行为,通常非常酷。

Basics 基础

To put an object under physics control, simply add a Rigidbody to it. When you do this, the object will be affected by gravity, and can collide with other objects in the world.

放一个物体到物理控件下,简单添加一个刚体给它。这时,物体将受重力影响,并可以与其他物体碰撞。

Rigidbodies 刚体

Rigidbodies are physically simulated objects. You use Rigidbodies for things that the player can push around, eg. crates or loose objects, or you can move Rigidbodies around directly by adding forces to it by scripting.

刚体是物理模拟物体。使用刚体的东西,玩家能够围绕推动。例如,包装箱或松散的物体,或可以移动的刚体,直接通过脚本施加力。

If you move the Transform of a non-Kinematic Rigidbody directly it may not collide correctly with other objects. Instead you should move a Rigidbody by applying forces and torque to it. You can also add Joints to rigidbodies to make the behavior more complex. For example, you could make a physical door or a crane with a swinging chain.

如果直接移动一个非运动学刚体变换,不会与其他物体发生碰撞,而是,通过应用力和扭矩来移动刚体。还可以添加Joints到刚体来制作更多复杂行为。例如,制作一扇物理门或一台带摆动链的起重机。

You also use Rigidbodies to bring vehicles to life, for example you can make cars using a Rigidbody, 4 Wheel Colliders and a script applying wheel forces based on the user's Input.

也可以使用刚体来使车辆有活力,例如,使用刚体制作轿车,4个车轮碰撞器和一个脚本,应用基于用户输入的车轮力。

You can make airplanes by applying forces to the Rigidbody from a script. Or you can create special vehicles or robots by adding various Joints and applying forces via scripting.

可以制作飞机,通过从脚本应用力给刚体。或者也可以通过加入各种关节,通过脚本应用力,来创建的特种车辆或机器人。

Rigidbodies are most often used in combination with primitive colliders.

刚体最常于原始碰撞器组合使用。

Tips 技巧:

  • You should never have a parent and child rigidbody together
    不应该父子同时具有刚体
  • You should never scale the parent of a rigidbody
    不应该缩放刚体的父级

Kinematic Rigidbodies 运动学刚体

A Kinematic Rigidbody is a Rigidbody that has the isKinematic option enabled. Kinematic Rigidbodies are not affected by forces, gravity or collisions. They are driven explicitly by setting the position and rotation of the Transform or animating them, yet they can interact with other non-Kinematic Rigidbodies.

运动学刚体是isKinematic选项启用的刚体。运动学刚体不受力,重力或碰撞影响。它们通过设置变换或动画的位置和旋转显式驱动,它们仍然可以与其他非运动学刚体互动。

Kinematic Rigidbodies correctly wake up other Rigidbodies when they collide with them, and they apply friction to Rigidbodies placed on top of them.

当运动学刚体与其他刚体碰撞时,正确将之唤醒,并其在它们上面时,应用摩擦力给刚体。

These are a few example uses for Kinematic Rigidbodies:

运动学刚体使用的几个例子:

  1. Sometimes you want an object to be under physics control but in another situation to be controlled explicitly from a script or animation. For example you could make an animated character whose bones have Rigidbodies attached that are connected with joints for use as a Ragdoll. Most of the time the character is under animation control, thus you make the Rigidbody Kinematic. But when he gets hit you want him to turn into a Ragdoll and be affected by physics. To accomplish this, you simply disable the isKinematic property.
    有 时候希望一个物体被物理系统控制但还有些情况下想要接受代码或动画的控制。比如你可能想一个骨骼附加了刚体并用关节相连的活动的角色变成人偶。大部分时间 里角色受动画控制,因此设置刚体为运动学的。但是当他收到打击你想让他变成人偶并受物理引擎控制,那只需要简单地把isKinematic属性取消掉。
  2. Sometimes you want a moving object that can push other objects yet not be pushed itself. For example if you have an animated platform and you want to place some Rigidbody boxes on top, you should make the platform a Kinematic Rigidbody instead of just a Collider without a Rigidbody.
    有时候你想让一个移动的物体可以推动别的物体但是自己不会被推动。比如,如果有一个活动的平台并想在上面放一些刚体盒子,那就应该设置平台为运动学刚体而不仅是不加刚体的碰撞器。
  3. You might want to have a Kinematic Rigidbody that is animated and have a real Rigidbody follow it using one of the available Joints.
    你可能想要一个动着的运动学刚体并用能用到的关节中的一种连着一个真正的刚体跟随。

Static Colliders 静态碰撞器

A Static Collider is a GameObject that has a Collider but not a Rigidbody. Static Colliders are used for level geometry which always stays at the same place and never moves around. You can add a Mesh Collider to your already existing graphical meshes (even better use the Import Settings Generate Colliders check box), or you can use one of the other Collider types.

一个静态碰撞器是一个包含碰撞器但不含刚体的游戏对象。静态碰撞器用于总是待在同一个地方不移动的水平几何体。你能把一个网格碰撞器添加到已存在的图形网格(甚至比用输入设置产生碰撞器复选框好用),或者你可以使用了另一种碰撞器类型。

You should never move a Static Collider on a frame by frame basis. Moving Static Colliders will cause an internal recomputation in PhysX that is quite expensive and which will result in a big drop in performance. On top of that the behaviour of waking up other Rigidbodies based on a Static Collider is undefined, and moving Static Colliders will not apply friction to Rigidbodies that touch it. Instead, Colliders that move should always be Kinematic Rigidbodies.

你不要逐帧移动 一个静态碰撞器,移动静态碰撞器将导致PhysX引擎的内部重置,非常耗费资源,而且会造成性能的极大下降。另外,基于一个静态碰撞器唤醒其他刚体的行为 是未定义的,而且移动静态碰撞器将不会对碰到它的刚体施加摩擦力。取而代之的是,要移动的碰撞器要保持是运动学刚体。

Character Controllers 角色控制器

You use Character Controllers if you want to make a humanoid character. This could be the main character in a third person platformer, FPS shooter or any enemy characters.

如果想制作一个类似人的角色那就使用角色控制器。这可以是第三人称平台游戏、第一人称射击游戏的主要角色或任何敌对角色。

These Controllers don't follow the rules of physics since it will not feel right (in Doom you run 90 miles per hour, come to halt in one frame and turn on a dime). Instead, a Character Controller performs collision detection to make sure your characters can slide along walls, walk up and down stairs, etc.

这类控制器不遵循物理规则因此它感觉上不对劲(在Doom中,你跑到了90英里每小时,然后马上停下而且可以极快的转身)。不过,角色控制器执行碰撞检测以保证你的角色可以沿着墙滑动,上下台阶等等。

Character Controllers are not affected by forces but they can push Rigidbodies by applying forces to them from a script. Usually, all humanoid characters are implemented using Character Controllers.

角色控制器不受力影响但是可以被由代码施加的力推动。通常,所有类似人的角色都用角色控制器来执行。

Character Controllers are inherently unphysical, thus if you want to apply real physics - Swing on ropes, get pushed by big rocks - to your character you have to use a Rigidbody, this will let you use joints and forces on your character. Character Controllers are always aligned along the Y axis, so you also need to use a Rigidbody if your character needs to be able to change orientation in space (for example under a changing gravity). However, be aware that tuning a Rigidbody to feel right for a character is hard due to the unphysical way in which game characters are expected to behave. Another difference is that Character Controllers can slide smoothly over steps of a specified height, while Rigidbodies will not.

角色控制器本身不具物理特性,因此如果想应用真正的物理作用 ——在绳上摇摆,被大石头推动——到你的角色,必须用刚体,这会允许你把铰链或力用到你的角色上。角色控制器永远沿Y轴对齐,因此,如果你的角色需要在空 间中改变方向那也必须用到刚体(比如在变化的引力控制下)。但是,要意识到调整一个刚体在角色上表现自然是很难的,因为游戏角色自身的非物理特性总想表现 出来。另一个困难是,角色控制器可以从特定高度的台阶上平滑地滑下,而刚体不会。

If you parent a Character Controller with a Rigidbody you will get a "Joint" like behavior.

如果你的角色控制器是一个刚体的子物体,他会表现的像"关节"一般。

Rigidbody 刚体

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 weight of the object in kilograms. 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.
    如果启用,物体将不受物理引擎驱动,只能由其变换操作。这通常用于移动平台体或如果你想动画一个具有HingeJoint附加的刚体。
  • 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).
    在场景使用Discrete碰撞检测,针对所有其他碰撞器。当测试碰撞,其针对他碰撞器将使用Discrete碰撞检测。用于标准碰撞(这是默认值)。
  •     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)
    使用Discrete碰撞检测针对动态碰撞器(带有刚体),Continuous碰撞检测针对静态网格碰撞器(不带刚体)。当针对这个刚体测试碰撞,刚体设置为Continuous Dynamic将使用连续碰撞检测。用于连续动态检测需要碰撞的物体。(这很大影响物理性能,如果你没有快速物体的碰撞问题,设置为Discrete。)
  •     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.
    使用连续碰撞检测,设置为Continuous 或 Continuous Dynamic,这将使用连续碰撞检测,针对静态网格碰撞器(不带刚体)。为所有其他碰撞器使用Discrete碰撞检测。用于快速移动的物体。
  • 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->Physics->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->Physics->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.

对于某些情况下,主要创建布娃娃效果,在物体的动画和物理之间开关控制,为此,刚体可以被标记为isKinematic。 刚体被标记为isKinematic,它将不受碰撞、力或任何其他物理的影响。这意味着,你必须直接通过变换组件操纵物体。动力学刚体会影响其他物体,但 自身不受物理影响。例如,附加到运动学物体的关节将约束附加的它们的任何其他刚体,并且运动学刚体会通过碰撞影响其他刚体。

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->Physics menu. View the Component Reference page of any individual Collider for more specific information:

从菜单Component->Physics添加碰撞器。浏览组件参考页面任一单独碰撞器阅读更多信息:

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.

网格碰撞器通常不能互相碰撞,如果一个网格碰撞器被标记为凸碰撞器(Convex),那么可以与其他碰撞器碰撞。典型的解决方案是使用原始的碰撞器,对于任何物体的移动,网格碰撞器用于静态背景物体。

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.

连续碰撞检测是为了防止快速移动 的碰撞器相互穿过的一个功能。当使用标准(Discrete)碰撞检测时,当一个碰撞器和另一个碰撞器的只有一帧的距离,并且在下一帧通过碰撞器,可能出 现这个问题。为了解决这个问题,可以在快速移动物体的刚体上启用连续碰撞检测。设置碰撞检测模式为Continuous防止刚体通过任意静态(如,非刚 体)网格碰撞器。设置为Continuous Dynamic也防止刚体穿过任意其他检测模式设置为Continuous 或 Continuous Dynamic的刚体。

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 crumbling 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.

如果建一个人类模型确保他的身高在Untiy是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,这里可以修改比例并从新导入网格。
[新版本是在导入的网格自带的FBXImporter组件中修改]

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.

如果游戏需要游戏物体需要不同比例的实例,可以正常调节变换缩放轴的值,缺点是物 理模拟时在实例的物体做更多工作,并可能导致游戏的性能下降。虽然他不是一个可怕的损失,但是缩放的效率下降得比移动和旋转多。还要记住的是,当使用父子 级时,非等比缩放可能产生不良行为。出于这些原因,最佳选项还是在3D建模软件中做好正确的比例。

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.
    如果你是通过其变换组件一个游戏物体移动,但要接收碰撞/触发消息,必须附加刚体到移动的物体。

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.

恒力(Constant Force)是添加恒力到刚体的一个快速工具,对于像火箭一个发生物体,这是一个伟大的工作,如果不想启动时有很大的速度,而是慢慢加速。


A rocket propelled forward by a Constant Force 由一个恒力助推火箭向前。

Properties 属性

  • 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.
    在局部坐标应用的扭矩向量。该物体将开始围绕这个向量旋转。向量的时间越长,旋转速度越快。

Details 细节

To make a rocket that accelerates forward set the Relative Force to be along the positive z-axis. Then use the Rigidbody's Drag property to make it not exceed some maximum velocity (the higher the drag the lower the maximum velocity will be). In the Rigidbody, also make sure to turn off gravity so that the rocket will always stay on its path.

为了使火箭加速前进,沿正Z轴,设置相对力。然后使用刚体的阻力属性,使其不超过最大速度(较高的摩擦力将会降低最大速度)。在刚体,也确保关闭了重力,因此火箭将总是保持其路径。

Hints 提示

  • To make an object flow upwards, add a Constant Force with the Force property having a positive Y value.
    要使物体向上飘动,沿正Y轴添加一个恒力。
  • To make an object fly forwards, add a Constant Force with the Relative Force property having a positive Z value.
    要使物体向前飞翔,沿正Z轴添加一个相对恒力。

Sphere Collider 球体碰撞器

The Sphere Collider is a basic sphere-shaped collision primitive.

球体碰撞器是一个基本的球形原始碰撞器。


A pile of Sphere Colliders 一堆球体碰撞器

Properties 属性

  • Material 材质
    Reference to the Physic Material that determines how this Collider interacts with others.
    引用何种物理材质决定了他和其他对象如何作用。
  • Is Trigger 是否碰撞器
    If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
    如激活,此碰撞器用于触发事件,并且被物理引擎忽略。
  • Radius 半径
    The size of the Collider. 碰撞器的大小
  • Center 中心
    The position of the Collider in the object's local space.
    碰撞器在对象本地坐标中的位置

Details 细节

The Sphere Collider can be resized to uniform scale, but not along individual axes. It works great for falling boulders, ping pong balls, marbles, etc.

球体碰撞器在三维上可以均等地调节大小,但不能只改变某一维(保持球体)。适合用于落石、乒乓球、弹球等等。

A standard Sphere Collider 一个标准的球体碰撞器

A standard Sphere Collider 一个标准的球体碰撞器

Colliders work with Rigidbodies to bring physics in Unity to life. Whereas Rigidbodies allow objects to be controlled by physics, Colliders allow objects to collide with each other. Colliders must be added to objects independently of Rigidbodies. A Collider does not necessarily need a Rigidbody attached, but a Rigidbody must be attached in order for the object to move as a result of collisions.

碰撞器作用于刚体使Unity中的物理作用生效。因为刚体允许对象被物理系统控制。碰撞器使对象之间产生碰撞作用。碰撞器必须独立于刚体加在对象上。碰撞器并不一定需要附加刚体,但是要使移动物体具有碰撞效果必须附加刚体。

When a collision between two Colliders occurs and if at least one of them has a Rigidbody attached, three collision messages are sent out to the objects attached to them. These events can be handled in scripting, and allow you to create unique behaviors with or without making use of the built-in NVIDIA PhysX engine.

当两个碰撞器间产生碰撞并且其中至少一个附加了刚体时,三个碰撞信息会发送给附加他们的对象,这些事件可以被脚本处理,而且允许用户可以选择自己写脚本或使用内置的NVIDIA PhysX引擎创建唯一的行为。

Triggers 触发器

An alternative way of using Colliders is to mark them as a Trigger, just check the IsTrigger property checkbox in the Inspector. Triggers are effectively ignored by the physics engine, and have a unique set of three trigger messages that are sent out when a collision with a Trigger occurs. Triggers are useful for triggering other events in your game, like cutscenes, automatic door opening, displaying tutorial messages, etc. Use your imagination!

一个可供选择的碰撞器使用方法是标记他们为触发器,仅需要选中检视面板中的 IsTrigger属性选择框。触发器不受物理引擎控制,当和一个触发器发生碰撞时会发出三个独特的触发信息。触发器用于触发你游戏中的其他事件,比如过 场动画、自动门开启、显示教程信息等等,发挥你的想象力吧!

Be aware that in order for two Triggers to send out trigger events when they collide, one of them must include a Rigidbody as well. For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below.

当然也应该意识到为了使两个触发器碰撞时发出碰撞事件,其中一个必须包含刚体。一个触发器和一个普通碰撞器碰撞,其中之一必须附加刚体。想了解不同类型碰撞的详细情况,可以参考下边进阶部分中的碰撞行为矩阵。

Friction and bouncyness 摩擦力和弹力

Friction, bouncyness and softness are defined in the Physic Material. The Standard Assets contain the most common physics materials. To use one of them click on the Physic Material drop-down and select one, eg. Ice. You can also create your own physics materials and tweak all friction values.

摩擦力、弹力和柔软度由物理材质中定义。标准资源( Standard Assets)中包含了大部分常见的物理材质。要使用只需点击物理材质上的下拉箭头然后选中一个,比如冰。你也可以创建你自己的物理材质并调整摩擦力的大小。

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 一个真实复合碰撞器设置
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.

网格碰撞器通常无法互相碰撞,如果一个网格碰撞器标记为凸起的(Convex),那么它可以和其他碰撞器碰撞。典型的解决方法是在移动对象上使用原始碰撞器而在静态的背景对象上使用网格碰撞器。

Hints 提示

  • To add multiple Colliders for an object, create child GameObjects and attach a Collider to each one. This allows each Collider to be manipulated independently.
    要给一个对象添加多个碰撞器,应该创建子对象并给每个子对象添加一个碰撞器。这使每个碰撞器可以被单独操作。
  • You can look at the gizmos in the Scene View to see how the Collider is being calculated on your object.
    可以通过场景视图(Scene View )中的线框(gizmos)来查看碰撞器在你的对象上的预期效果。
  • Colliders do their best to match the scale of an object. If you have a non-uniform scale (a scale which is different in each direction), only the Mesh Collider can match completely.
    碰撞器尽量匹配对象的比例。如果有一组不规则伸缩(每一维度上的比例都不相同),只能使用网格碰撞器才能完全匹配。
  • If you are moving an object through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.
    如果你想接收通过Transform组件移动的对象的碰撞/触发信息,你必须给移动对象附加刚体。
  • If you make an explosion, it can be very effective to add a rigidbody with lots of drag and a sphere collider to it in order to push it out a bit from the wall it hits.
    如果你制作一个爆炸,添加带有很多阻力和一个球体碰撞器为了使他碰到墙体,产生有效的爆炸。

Advanced 进阶

Collider combinations碰撞器组合

There are numerous different combinations of collisions that can happen in Unity. Each game is unique, and different combinations may work better for different types of games. If you're using physics in your game, it will be very helpful to understand the different basic Collider types, their common uses, and how they interact with other types of objects.

Unity中有许多不同的碰撞组合。每个游戏都很独特,不同的组合可能更好地适用于不同类型的游戏。如果你在游戏中使用了物理效果,那理解不同的基本碰撞类型会很有帮助,包括它们的常用形式及如何和其他类型的对象作用。

Static Collider 静态碰撞器

These are GameObjects that do not have a Rigidbody attached, but do have a Collider attached. These objects should remain still, or move very little. These work great for your environment geometry. They will not move if a Rigidbody collides with them.

指的是没有附加刚体而附加了碰撞器的游戏对象。这类对象会保持静止或者很轻微的移动。对于环境模型十分好用,当和刚体碰撞时而不会移动。

Rigidbody Collider 刚体碰撞器

These GameObjects contain both a Rigidbody and a Collider. They are completely affected by the physics engine through scripted forces and collisions. They might collide with a GameObject that only contains a Collider. These will likely be your primary type of Collider in games that use physics.

指的是同时附加了刚体和碰撞器的游戏对象。通过脚本的力量和碰撞完全受物理引擎的影响。可以和只包含碰撞器的游戏对象碰撞。将会成为你游戏中使用物理效果的基本类型碰撞器。

Kinematic Rigidbody Collider 运动学刚体碰撞器

This GameObject contains a Collider and a Rigidbody which is marked IsKinematic. To move this GameObject, you modify its Transform Component, rather than applying forces. They're similar to Static Colliders but will work better when you want to move the Collider around frequently. There are some other specialized scenarios for using this GameObject.

指的是同时包含碰撞器和刚体,并且激活IsKinematic的一类游戏对象,要移动这类游戏对象,要修改它的Transform组件,而不是用力。它们很像静态碰撞器不过对于想要不停地到处移动的碰撞器很好用。这类游戏对象还有许多其他的独特使用情景。

This object can be used for circumstances in which you would normally want a Static Collider to send a trigger event. Since a Trigger must have a Rigidbody attached, you should add a Rigidbody, then enable IsKinematic. This will prevent your Object from moving from physics influence, and allow you to receive trigger events when you want to.

这类对象可以用于你通常希望用静态碰撞器发出触发事件的情形下。因为触发器必须要有刚体,你应该添加刚体然后启用IsKinematic。这会阻止你的对象因物理作用而移动并且允许接收你希望得到的触发事件。

Kinematic Rigidbodies can easily be turned on and off. This is great for creating ragdolls, when you normally want a character to follow an animation, then turn into a ragdoll when a collision occurs, prompted by an explosion or anything else you choose. When this happens, simply turn all your Kinematic Rigidbodies into normal Rigidbodies through scripting.

运动学刚体启用与否很容易控制。这对创建人偶十分适用,通常,当你希望一个角色依照动画活动,然后由于爆炸或者其他你选择的情况而引起的碰撞导致其变为人偶。这种情况下,很简单,只需要通过脚本将运动学刚体改为普通刚体。

If you have Rigidbodies come to rest so they are not moving for some time, they will "fall asleep". That is, they will not be calculated during the physics update since they are not going anywhere. If you move a Kinematic Rigidbody out from underneath normal Rigidbodies that are at rest on top of it, the sleeping Rigidbodies will "wake up" and be correctly calculated again in the physics update. So if you have a lot of Static Colliders that you want to move around and have different object fall on them correctly, use Kinematic Rigidbody Colliders.

如果有刚体有时候变得静止不动了,那么它们就是进入休眠了。意味着它们将不受物理变化 影响,也就不会移动。如果你把一个运动学刚体从一个休眠的普通刚体下边移走,那休眠的刚体就会被唤醒并重新被物理变化时时影响。所以如果你有许多希望四处 移动并有不同的对象要恰好砸到它们的静态碰撞器,那就用运动学刚体碰撞器吧。

Collision action matrix 碰撞行为矩阵

Depending on the configurations of the two colliding Objects, a number of different actions can occur. The chart below outlines what you can expect from two colliding Objects, based on the components that are attached to them. Some of the combinations only cause one of the two Objects to be affected by the collision, so keep the standard rule in mind - physics will not be applied to objects that do not have Rigidbodies attached.

基于两个碰撞对象的配置,可以产生很多不同的效果。下表概括了基于附加不同组件的两个碰撞对象所产生的效果。其中有些组合只能导致碰撞的两个对象中的一个受到影响,.所以考虑到保持标准的规则-物理效果将不会对没有附加刚体的对象生效。

Collision detection occurs and messages are sent upon collision
碰撞后有碰撞检测并有碰撞信息发出
Static Collider
静态碰撞器
Rigidbody Collider
刚体碰撞器
Kinematic
Rigidbody Collider
运动学刚体碰撞器
Static
Trigger Collider
静态触发碰撞器
Rigidbody
Trigger Collider
刚体触发碰撞器
Kinematic Rigidbody
Trigger Collider
运动学刚体触发碰撞器
Static Collider 静态碰撞器 Y
Rigidbody Collider 刚体碰撞器 Y Y Y
Kinematic Rigidbody Collider
运动学刚体碰撞器
Y
Static Trigger Collider
静态触发碰撞器
Rigidbody Trigger Collider
刚体触发碰撞器
Kinematic Rigidbody Trigger Collider
运动学刚体触发碰撞器
Trigger messages are sent upon collision
碰撞后有触发信息
Static Collider
静态碰撞器
Rigidbody Collider
刚体碰撞器
Kinematic
Rigidbody Collider
运动学刚体碰撞器
Static
Trigger Collider
静态触发碰撞器
Rigidbody
Trigger Collider
刚体触发碰撞器
Kinematic Rigidbody
Trigger Collider
运动学刚体触发碰撞器
Static Collider 静态碰撞器 Y Y
Rigidbody Collider 刚体碰撞器 Y Y Y
Kinematic Rigidbody Collider
运动学刚体碰撞器
Y Y Y
Static Trigger Collider
静态触发碰撞器
Y Y Y Y
Rigidbody Trigger Collider
刚体触发碰撞器
Y Y Y Y Y Y
Kinematic Rigidbody Trigger Collider
运动学刚体触发碰撞器
Y Y Y Y Y Y

Layer-Based Collision Detection 基于层的碰撞检测

In Unity 3.x we introduce something called Layer-Based Collision Detection, and is that you can now selectively tell Unity GameObjects to collide with specific layers they are attached to. For more info, you can click here

在Unity3以后版本,我们介绍了一种称为"基于层的碰撞检测"(Layer-Based Collision Detection)的东西,可以让你有选择地控制Unity对象和他们附加的特定层碰撞。点击此处获取更多信息。

Box Collider 盒碰撞器

The Box Collider is a basic cube-shaped collision primitive.

盒碰撞器是一个基本的立方体原始碰撞器。

盒碰撞器 Box Collider
A pile of Box Colliders 一堆盒碰撞器

Properties 属性

  • Material 材质
    Reference to the Physic Material that determines how this Collider interacts with others.
    引用何种物理材质决定了他和其他对象如何作用。
  • Is Trigger 是否触发器
    If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
    如激活,此碰撞器用于触发事件,并且被物理引擎忽略。
  • Size 大小
    The size of the Collider in the X, Y, Z directions.
    在X、Y、Z三维上的碰撞器尺寸。
  • Center 中心
    The position of the Collider in the object's local space.
    碰撞器在对象本地坐标中的位置

Details 细节

The Box Collider can be resized into different shapes of rectangular prisms. It works great for doors, walls, platforms, etc. It is also effective as a human torso in a ragdoll or as a car hull in a vehicle. Of course, it works perfectly for just boxes and crates as well!

盒碰撞器可以被调整成不同大小的长方体。能够很好地用于门、墙、平台等等。也能够用于角色的躯干或者车辆等交通工具的外壳。当然,只是用在盒子或者箱子上表现也十分完美。

A standard Box Collider 一个标准的盒碰撞器
A standard Box Collider 一个标准的盒碰撞器

Colliders work with Rigidbodies to bring physics in Unity to life. Whereas Rigidbodies allow objects to be controlled by physics, Colliders allow objects to collide with each other. Colliders must be added to objects independently of Rigidbodies. A Collider does not necessarily need a Rigidbody attached, but a Rigidbody must be attached in order for the object to move as a result of collisions.

盒碰撞器作用于刚体使Unity中的物理作用生效。因为刚体允许对象被物理系统控制。碰撞器使对象之间产生碰撞作用。碰撞器必须独立于刚体加在对象上。碰撞器并不一定需要附加刚体,但是要使移动物体具有碰撞效果必须附加刚体。

When a collision between two Colliders occurs and if at least one of them has a Rigidbody attached, three collision messages are sent out to the objects attached to them. These events can be handled in scripting, and allow you to create unique behaviors with or without making use of the built-in NVIDIA PhysX engine.

当两个碰撞器间产生碰撞并且其中至少一个附加了刚体时,三个碰撞信息会发送给附加他们的对象,这些事件可以被脚本处理,而且允许用户可以选择自己写脚本或使用内置的NVIDIA PhysX引擎创建唯一的行为。

Triggers 触发器

An alternative way of using Colliders is to mark them as a Trigger, just check the IsTrigger property checkbox in the Inspector. Triggers are effectively ignored by the physics engine, and have a unique set of three trigger messages that are sent out when a collision with a Trigger occurs. Triggers are useful for triggering other events in your game, like cutscenes, automatic door opening, displaying tutorial messages, etc. Use your imagination!

一个可供选择的碰撞器使用方法是标记他们为触发器,仅需要选中检视面板中的 IsTrigger属性选择框。触发器不受物理引擎控制,当和一个触发器发生碰撞时会发出三个独特的触发信息。触发器用于触发你游戏中的其他事件,比如过 场动画、自动门开启、显示教程信息等等,发挥你的想象力吧!

Be aware that in order for two Triggers to send out trigger events when they collide, one of them must include a Rigidbody as well. For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below.

当然也应该意识到为了使两个触发器碰撞时发出碰撞事件,其中一个必须包含刚体。一个触发器和一个普通碰撞器碰撞,其中之一必须附加刚体。想了解不同类型碰撞的详细情况,可以参考下边进阶部分中的碰撞行为矩阵。

Friction and bouncyness 摩擦力和弹力

Friction, bouncyness and softness are defined in the Physic Material. The Standard Assets contain the most common physics materials. To use one of them click on the Physic Material drop-down and select one, eg. Ice. You can also create your own physics materials and tweak all friction values.

摩擦力、弹力和柔软度由物理材质中定义。标准资源( Standard Assets)中包含了大部分常见的物理材质。要使用只需点击物理材质上的下拉箭头然后选中一个,比如冰。你也可以创建你自己的物理材质并调整摩擦力的大小。

Mesh Collider 网格碰撞器

The Mesh Collider takes a Mesh Asset and builds its Collider based on that mesh. It is far more accurate for collision detection than using primitives for complicated meshes. Mesh Colliders that are marked as Convex can collide with other Mesh Colliders.

网格碰撞器利用一个网格资源并在其上构建碰撞器。对于复杂网状模型上的碰撞检测,它要比应用原始碰撞器精确的多。标记为凸起的(Convex )的网格碰撞器才能够和其他网格碰撞器发生碰撞。

Mesh Collider 网格碰撞器
A Mesh Collider used on level geometry 用于台阶状物体的网格碰撞器

Properties 属性

  • Material 材质
    Reference to the Physic Material that determines how this Collider interacts with others.
    引用何种物理材质决定了他和其他对象如何作用。
  • Is Trigger 是否触发器
    If enabled, this Collider is used for triggering events, and is ignored by the physics engine.
    如激活,此碰撞器用于触发事件,并且被物理引擎忽略。
  • Mesh 网格
    Reference to the Mesh to use for collisions.
    用于碰撞所引用的网格
  • Smooth Sphere Collisions
    平滑性状碰撞
    When this is enabled, collision mesh normals are smoothed. You should enable this on smooth surfaces eg. rolling terrain without hard edges to make sphere rolling smoother.
    当被激活,碰撞网格法线是平滑的。用于平滑表面比如由没有棱角的平滑起伏组成的起伏地标时应该激活。
  • Convex 凸起的
    If enabled, this Mesh Collider will collide with other Mesh Colliders. Convex Mesh Colliders are limited to 255 triangles.
    如激活,该网格碰撞器将会和其他网格碰撞器碰撞。凸起的网格碰撞器限制在255个三角形面内。

Details 细节

The Mesh Collider builds its collision representation from the Mesh attached to the GameObject, and reads the properties of the attached Transform to set its position and scale correctly.

网格碰撞器通过附加在游戏对象上的网格构建碰撞效果,并严格按照所附加对象的Transform属性来设定其位置和大小比例。

Collision meshes use backface culling. If an object collides with a mesh that will be backface culled graphically it will also not collide with it physically.

碰撞网格使用背面剔除(或译背面拣选,指正面多边形挡住了在它后面的背面多边形,Direct3D将通过拣选(即删除多余的处理过程)背面多边形来提高效率的过程。)如果一个对象和被背面剔除的网格碰撞,那也不会在物理上碰撞。

There are some limitations when using the Mesh Collider. Usually, two Mesh Colliders cannot collide with each other. All Mesh Colliders can collide with any primitive Collider. If your mesh is marked as Convex, then it can collide with other Mesh Colliders.

使用网格碰撞器有一些限制条件。通常,两个网格碰撞器之间不会发生碰撞。所有的网格碰撞器可以和任何原始碰撞器碰撞。如果网格标记为凸起的(Convex),那么就可以和其他网格碰撞器碰撞。

Colliders work with Rigidbodies to bring physics in Unity to life. Whereas Rigidbodies allow objects to be controlled by physics, Colliders allow objects to collide with each other. Colliders must be added to objects independently of Rigidbodies. A Collider does not necessarily need a Rigidbody attached, but a Rigidbody must be attached in order for the object to move as a result of collisions.

碰撞器作用于刚体使Unity中的物理作用生效。因为刚体允许对象被物理系统控制。碰撞器使对象之间产生碰撞作用。碰撞器必须独立于刚体加在对象上。碰撞器并不一定需要附加刚体,但是要使移动物体具有碰撞效果必须附加刚体。

When a collision between two Colliders occurs and if at least one of them has a Rigidbody attached, three collision messages are sent out to the objects attached to them. These events can be handled in scripting, and allow you to create unique behaviors with or without making use of the built-in NVIDIA PhysX engine.

当两个碰撞器间产生碰撞并且其中至少一个附加了刚体时,三个碰撞信息会发送给附加他们的对象,这些事件可以被脚本处理,而且允许用户可以选择自己写脚本或使用内置的NVIDIA PhysX引擎创建唯一的行为。

Triggers

An alternative way of using Colliders is to mark them as a Trigger, just check the IsTrigger property checkbox in the Inspector. Triggers are effectively ignored by the physics engine, and have a unique set of three trigger messages that are sent out when a collision with a Trigger occurs. Triggers are useful for triggering other events in your game, like cutscenes, automatic door opening, displaying tutorial messages, etc. Use your imagination!

一个可供选择的碰撞器使用方法是标记他们为触发器,仅需要选中检视面板中的 IsTrigger属性选择框。触发器不受物理引擎控制,当和一个触发器发生碰撞时会发出三个独特的触发信息。触发器用于触发你游戏中的其他事件,比如过 场动画、自动门开启、显示教程信息等等,发挥你的想象力吧!

Be aware that in order for two Triggers to send out trigger events when they collide, one of them must include a Rigidbody as well. For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below.

当然也应该意识到为了使两个触发器碰撞时发出碰撞事件,其中一个必须包含刚体。一个触发器和一个普通碰撞器碰撞,其中之一必须附加刚体。想了解不同类型碰撞的详细情况,可以参考下边进阶部分中的碰撞行为矩阵。

Friction and bouncyness 摩擦力和弹力

Friction, bouncyness and softness are defined in the Physic Material. The Standard Assets contain the most common physics materials. To use one of them click on the Physic Material drop-down and select one, eg. Ice. You can also create your own physics materials and tweak all friction values.

摩擦力、弹力和柔软度由物理材质中定义。标准资源( Standard Assets)中包含了大部分常见的物理材质。要使用只需点击物理材质上的下拉箭头然后选中一个,比如冰。你也可以创建你自己的物理材质并调整摩擦力的大小。

Hints 提示

  • Mesh Colliders cannot collide with each other unless they are marked as Convex. Therefore, they are most useful for background objects like environment geometry.
    除非被标记为凸起的(Convex),否则网格碰撞器间不会发生碰撞。因此,它们最常被用于背景对象比如环境布景。
  • Convex Mesh Colliders must be fewer than 255 triangles.
    凸起的网格碰撞器含有的三角形面不能多于255个。
  • Primitive Colliders are less costly for objects under physics control.
    原型控制器对于对象的物理控制更加节省资源。
  • When you attach a Mesh Collider to a GameObject, its Mesh property will default to the mesh being rendered. You can change that by assigning a different Mesh.
    当为游戏对象附加了网格碰撞器,其网格属性将被定义为用于渲染的网格,可以通过指派其他网格来改变。
  • To add multiple Colliders for an object, create child GameObjects and attach a Collider to each one. This allows each Collider to be manipulated independently.
    要给一个对象添加多个碰撞器,应该创建子对象并给每个子对象添加一个碰撞器。这使每个碰撞器可以被单独操作。
  • You can look at the gizmos in the Scene View to see how the Collider is being calculated on your object.
    可以通过场景视图(Scene View )中的线框(gizmos)来查看碰撞器在你的对象上的预期效果。
  • Colliders do their best to match the scale of an object. If you have a non-uniform scale (a scale which is different in each direction), only the Mesh Collider can match completely.
    碰撞器尽量匹配对象的比例。如果有一组不规则伸缩(每一维度上的比例都不相同),只能使用网格碰撞器才能完全匹配。
  • If you are moving an object through its Transform component but you want to receive Collision/Trigger messages, you must attach a Rigidbody to the object that is moving.
    如果你想接收通过Transform组件移动的对象的碰撞/触发信息,你必须给移动对象附件刚体。

Physic Material 物理材质

The Physic Material is used to adjust friction and bouncing effects of colliding objects.

物理材质用来调节碰撞物体的摩擦力和弹力效果。

To create a Physic Material select Assets->Create->Physic Material from the menu bar. Then drag the Physic Material from the Project View onto a Collider in the scene.

要创建物理材质从菜单栏选择Assets->Create->Physic Material。然后从项目视图拖拽物理材质到场景的一个碰撞器上。


The Physic Material InspectorXS

Properties 属性

  • Dynamic Friction 动态摩擦力
    The friction used when already moving. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it come to rest very quickly unless a lot of force or gravity pushes the object.
    用于已经移动时的摩擦力。通常值在0到1之间。为0的值感觉像冰,值为1将很快停下来,除非有很多力或重力推动物体。
  • Static Friction 静态摩擦力
    The friction used when an object is laying still on a surface. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it very hard to get the object moving.
    当物体放置在表面上是静止的时,使用的摩擦力。通常值在0到1之间。为0的值感觉像冰。为1的值将使它很难让物体移动。
  • Bouncyness 弹力
    How bouncy is the surface? A value of 0 will not bounce. A value of 1 will bounce without any loss of energy.
    表面有多少弹性?0值将不反弹。1值反弹将没有任何能量损失。
  • Friction Combine Mode 摩擦力结合模式
    How the friction of two colliding objects is combined.
    两个碰撞物体的摩擦力是如何结合起来。
  •     Average 合并
    The two friction values are averaged. 两个摩擦力值被合并。
  •     Min 最小
    The smallest of the two values is used. 使用两个值的最小值。
  •     Max 最大
    The largest of the two values is used. 使用两个值的最大值。
  •     Multiply 相乘
    The friction values are multiplied with each other. 摩擦力的值彼此相乘
  • Bounce Combine 弹力结合
    How the bouncyness of two colliding objects is combined. It has the same modes as Friction Combine Mode
    两个碰撞物体的弹力如何结合。具有相同的摩擦结合模式
  • Friction Direction 2 摩擦力方向
    The direction of anisotropy. Anisotropic friction is enabled if this direction is not zero. Dynamic Friction 2 and Static Friction 2 will be applied along Friction Direction 2.
    各向异性的方向。如果该方向不为0,各向异性摩擦力被启用。 Dynamic Friction 2和Static Friction 2将被沿着Friction Direction 2应用。
  • Dynamic Friction 2 动态摩擦力
    If anisotropic friction is enabled, DynamicFriction2 will be applied along Friction Direction 2.
    如果各向异性摩擦力被启用,DynamicFriction2将沿着Friction Direction 2应用。
  • Static Friction 2 静态摩擦力
    If anisotropic friction is enabled, StaticFriction2 will be applied along Friction Direction 2.
    如果各向异性摩擦力被启用,StaticFriction2将沿着Friction Direction 2应用。

Details 细节

Friction is the quantity which prevents surfaces from sliding off each other. This value is critical when trying to stack objects. Friction comes in two forms, dynamic and static. Static friction is used when the object is lying still. It will prevent the object from starting to move. If a large enough force is applied to the object it will start moving. At this point Dynamic Friction will come into play. Dynamic Friction will now attempt to slow down the object while in contact with another.

摩擦力是防止从彼此表面画出的数量。当尝试堆积物体是,这个值是至关重要的。摩擦有2种形 式,动态和静态。当物体是静止状态时,使用静态摩擦力,这将防止物体移动,如果有足够大的力施加给物体,将会开始移动,此时动态摩擦力开始作用。当该物体 与其他物体碰撞时,动态摩擦力将尝试放慢该物体。

Hints 提示

  • Don't try to use a standard physic material for the main character. Make a customized one and get it perfect.
    不要为主角尝试使用一个标准的物理材质,自定义一个,以使获得更好效果。

Hinge Joint 铰链关节

The Hinge Joint groups together two Rigidbodies, constraining them to move like they are connected by a hinge. It is perfect for doors, but can also be used to model chains, pendulums, etc.

铰链关节由两个刚体组成,约束它们像连在一个铰链上一样运动,适用于门,不过对于典型的链子、钟摆等同样适用。


The Hinge Joint Inspector 铰链关节检视面板

Properties 属性

  • Connected Body 连接体
    Optional reference to the Rigidbody that the joint is dependent upon. If not set, the joint connects to the world.
    为刚体指定的关节连接物,如不设定,则与世界相连
  • Anchor 锚点
    The position of the axis around which the body swings. The position is defined in local space.
    主体摇摆围绕的锚点坐标,基于本地坐标系
  • Axis 坐标轴
    The direction of the axis around which the body swings. The direction is defined in local space.
    摇摆方向的坐标,基于本地坐标系
  • Use Spring 是否使用弹簧
    Spring makes the Rigidbody reach for a specific angle compared to its connected body.
    弹簧使刚体相对它连接的主体达到一个特定的角度
  • Spring 弹簧
    Properties of the Spring that are used if Use Spring is enabled.
    用于如激活Use Spring的弹簧属性
  •     Spring 弹簧力
    The force the object asserts to move into the position.
    维持对象移动到一定位置的力
  •     Damper 阻尼
    The higher this value, the more the object will slow down.
    值越大,对象移动越慢
  •     Target Position 目标角度
    Target angle of the spring. The spring pulls towards this angle measured in degrees.
    弹簧的目标角度。弹簧拉向这个角度,以角为单位
  • Use Motor 是否使用马达
    The motor makes the object spin around.
    Motor使对象旋转
  • Motor 马达
    Properties of the Motor that are used if Use Motor is enabled.
    用于如激活Use Motor的马达属性
  •     Target Velocity 目标速率
    The speed the object tries to attain. 对象设法达到的速度
  •     Force
    The force applied in order to attain the speed. 用于达到目标速率的力
  •     Free Spin 自由转动
    If enabled, the motor is never used to brake the spinning, only accelerate it.
    如果启用,Motor永远不会破坏旋转,只会加速
  • Use Limits 是否有限制
    If enabled, the angle of the hinge will be restricted within the Min & Max values.
    如果启用,铰链的角度将被限制在最大和最小之间
  • Limits 限制
    Properties of the Limits that are used if Use Limits is enabled.
    用于如启用Use Limits 的边界属性
  •     Min 最小
    The lowest angle the rotation can go. rotation能达到的最小角度
  •     Max 最大
    The highest angle the rotation can go. rotation能达到的最大角度
  •     Min Bounce 最小弹跳
    How much the object bounces when it hits the minimum stop.
    物体碰触最小限制时的弹跳值
  •     Max Bounce 最大弹跳
    How much the object bounces when it hits the maximum stop.
    物体碰触最大限制时的弹跳值
  • 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.
    允许这个铰链破损的扭矩

Details 细节

A single Hinge Joint should be applied to a GameObject. The hinge will rotate at the point specified by the Anchor property, moving around the specified Axis property. You do not need to assign a GameObject to the joint's Connected Body property. You should only assign a GameObject to the Connected Body property if you want the joint's Transform to be dependent on the attached object's Transform.

单 独的铰链关节要连在游戏对象上。铰链会绕着Anchor 属性指定的点,沿着 指定的Axis 属性方向移动。不需要给关节的Connected Body 属性分配游戏对象。只有希望关节的Transform依赖附加对象的Transform时,才需要分配游戏对象给Connected Body属性。

Think about how the hinge of a door works. The Axis in this case is up, positive along the Y axis. The Anchor is placed somewhere at the intersection between door and wall. You would not need to assign the wall to the Connected Body, because the joint will be connected to the world by default.

想一想门的铰链如何工作。Axis在这种情况下是向上的,沿Y轴正向。Anchor在门和墙交点的某处。不需要指定墙给Connected Body,因为关节默认会和世界相连。

Now think about a doggy door hinge. The doggy door's Axis would be sideways, positive along the relative X axis. The main door should be assigned as the Connected Body, so the doggy door's hinge is dependent on the main door's Rigidbody.

现在再想想狗门铰链。狗门的Axis 应该是侧向的,沿着X轴的正向。正门应该指定为Connected Body,这样狗门的铰链即依赖于正门的Rigidbody。

Chains 链条

Multiple Hinge Joints can also be strung together to create a chain. Add a joint to each link in the chain, and attach the next link as the Connected Body.

多个铰链关节也可以串起来变成一条链条。给链条的每一环添加一个关节,并附加下一环为其Connected Body。

Hints 提示

  • You do not need to assign a Connected Body to your joint for it to work.
    不需要指派Connected Body 来使关节运转。
  • Use Break Force in order to make dynamic damage systems. This is really cool as it allows the player to break a door off its hinge by blasting it with a rocket launcher or running into it with a car.
    用Break Force来制作动态破坏的系统。这确实很酷,可以让玩家用火箭发射器爆破或者用疾驶的汽车撞,来把门从铰链处弄碎。
  • The Spring, Motor, and Limits properties allow you to fine-tune your joint's behaviors.
    调整Spring、Motor和Limits属性可以改变关节的作用。

Spring Joint 弹簧关节

The Spring Joint groups together two Rigidbodies, constraining them to move like they are connected by a spring.

弹簧关节是两个刚体组。制约它们就像弹簧一样。


The Spring Joint Inspector 弹簧关节检视面板

Properties 属性

  • Connected Body 连接体
    Optional reference to the Rigidbody that the joint is dependent upon.
    可选项,关节依赖的刚体。
  • Anchor
    Position in the object's local space (at rest) that defines the center of the joint. This is not the point that the object will be drawn toward.
    在物体局部空间的位置(静止时)定义关节的中心。这不是物体将拉向的点。
  •     X
    Position of the joint's local center along the X axis.
    关节局部中心沿着X轴的位置
  •     Y
    Position of the joint's local center along the Y axis.
    关节局部中心沿着Y轴的位置
  •     Z
    Position of the joint's local center along the Z axis.
    关节局部中心沿着Z轴的位置
  • Spring 弹簧力
    Strength of the spring. 弹簧的强度。
  • Damper 阻尼器
    Amount that the spring is reduced when active.
    当激活时,降低弹簧的强度数。
  • Min Distance 最小距离
    Distances greater than this will not cause the Spring to activate.
    大于这个距离,不会使弹簧激活
  • Max Distance 最大距离
    Distances less than this will not cause the Spring to activate.
    小于这个距离,不会使弹簧激活
  • 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.
    应用到这个关节的断开扭矩。

Details 细节

Spring Joints allows a Rigidbodied GameObject to be pulled toward a particular "target" position. This position will either be another Rigidbodied GameObject or the world. As the GameObject travels further away from this "target" position, the Spring Joint applies forces that will pull it back to its original "target" position. This creates an effect very similar to a rubber band or a slingshot.

弹簧关节允许一个刚体游戏物体拉向一个特定的目标位置。这个位置可以是另一个刚体游戏物体或世界位置。如游戏物体从这个目标位置离开更远,该弹簧关节应用力将拉回原来的目标位置。这将创建一个非常像橡皮筋或弹弓的效果。

The "target" position of the Spring is determined by the relative position from the Anchor to the Connected Body (or the world) when the Spring Joint is created, or when Play mode is entered. This makes the Spring Joint very effective at setting up Jointed characters or objects in the Editor, but is harder to create push/pull spring behaviors in runtime through scripting. If you want to primarily control a GameObject's position using a Spring Joint, it is best to create an empty GameObject with a Rigidbody, and set that to be the Connected Rigidbody of the Jointed object. Then in scripting you can change the position of the Connected Rigidbody and see your Spring move in the ways you expect.

当创建关节时,或进入播放模式时,弹簧的目标位置通过从锚到连接体(或世界)的相 对位置来确定。这使弹簧关节在编辑器设置角色或物体关节非常有效,但是通过脚本在运行时很难创建推/拉弹簧行为。如果想主要控制一个游戏物体的位置使用弹 簧关节,最好创建一个带有刚体的空游戏对象,设置到关节物体的连接体。然后通过脚本改变连接刚体的位置,浏览看弹簧移动是否期望的方式。

Connected Rigidbody 连接刚体

You do not need to use a Connected Rigidbody for your joint to work. Generally, you should only use one if your object's position and/or rotation is dependent on it. If there is no Connected Rigidbody, your Spring will connect to the world.

在使用关节时,不是必须使用连接刚体。通常,如果物体的位置和/或旋转依赖于它,应该仅适用一个连接刚体。如果没有连接刚体,弹簧将连接到世界空间。

Spring & Damper 弹簧力和阻尼器

Spring is the strength of the force that draws the object back toward its "target" position. If this is 0, then there is no force that will pull on the object, and it will behave as if no Spring Joint is attached at all.

弹簧力是力的强度,拉回物体到它的目标位置。如果为0,那么物体上将没有拉力,这个行为就像没有弹簧关节附近在物体上。

Damper is the resistance encountered by the Spring force. The lower this is, the springier the object will be. As the Damper is increased, the amount of bounciness caused by the Joint will be reduced.

阻尼器是弹簧力所遇到的阻力。较低的值,弹簧更有弹性。增加阻尼值,关节产生反弹量将会减少。

Min & Max Distance 最小和最大距离

If the position of your object falls in-between the Min & Max Distances, then the Joint will not be applied to your object. The position must be moved outside of these values for the Joint to activate.

如果物体的位置在最小和最大距离之间,那么关节不会被应用到物体,位置必须在这些值之外,关节才会激活。

Hints 提示

  • You do not need to assign a Connected Body to your Joint for it to work.
    在使用关节时,不是必须指定连接刚体。
  • Set the ideal positions of your Jointed objects in the Editor prior to entering Play mode.
    进入播放模式之前,关节的物体到理想位置。
  • Spring Joints require your object to have a Rigidbody attached.
    弹簧关节需要物体必须附近刚体。
iOS

iOS physics optimization hints can be found here.
iOS 物理优化技巧在这里

页面最后更新: 2011-01-12

分类:Manual|评论: 0|浏览: 228 翻译: U_鹰
评论
暂无评论
发表评论
用户名:

评论审核后才会显示!