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 技巧:
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: 运动学刚体使用的几个例子:
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物理引擎交互。
Properties 属性
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. 碰撞器是另一种组件,必须和刚体一起添加以便产生碰撞。如果两个刚体彼此碰撞,物理引擎将不计算碰撞,除非两个物体都有一个碰撞器附加。碰撞器刚体将通过彼此碰撞物理模拟。
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. 复合碰撞器是原始碰撞器的组合,集体作为一个 单一的碰撞器使用。当你有一个复杂的网格使用碰撞时,这就派上用场了,但不能使用网格碰撞器。要创建复合碰撞器,创建碰撞物体的子物体,然后添加原始碰撞 器到每个子物体,这就容易来定位、旋转和缩放每个碰撞器,它们是各自独立的。
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,这里可以修改比例并从新导入网格。 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 提示
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)是添加恒力到刚体的一个快速工具,对于像火箭一个发生物体,这是一个伟大的工作,如果不想启动时有很大的速度,而是慢慢加速。
Properties 属性
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 提示
Sphere Collider 球体碰撞器The Sphere Collider is a basic sphere-shaped collision primitive. 球体碰撞器是一个基本的球形原始碰撞器。
Properties 属性
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 一个标准的球体碰撞器 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. 复合碰撞器是组合原始碰撞器,共同扮演单个碰 撞器的角色。当你在碰撞器上使用了一组复杂的网格而网格碰撞器不能用时,这是很好的选择。要创建复合碰撞器,只需给你的碰撞器对象创建子对象,然后为每个 子对象添加原始碰撞器。这就允许你轻易地移动、旋转或者伸缩每个碰撞器,并使他们互相之间互不影响。
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 提示
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. 基于两个碰撞对象的配置,可以产生很多不同的效果。下表概括了基于附加不同组件的两个碰撞对象所产生的效果。其中有些组合只能导致碰撞的两个对象中的一个受到影响,.所以考虑到保持标准的规则-物理效果将不会对没有附加刚体的对象生效。
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. 盒碰撞器是一个基本的立方体原始碰撞器。
Properties 属性
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! 盒碰撞器可以被调整成不同大小的长方体。能够很好地用于门、墙、平台等等。也能够用于角色的躯干或者车辆等交通工具的外壳。当然,只是用在盒子或者箱子上表现也十分完美。
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 )的网格碰撞器才能够和其他网格碰撞器发生碰撞。
Properties 属性
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引擎创建唯一的行为。 TriggersAn 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 提示
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。然后从项目视图拖拽物理材质到场景的一个碰撞器上。
Properties 属性
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 提示
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. 铰链关节由两个刚体组成,约束它们像连在一个铰链上一样运动,适用于门,不过对于典型的链子、钟摆等同样适用。
Properties 属性
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 提示
Spring Joint 弹簧关节The Spring Joint groups together two Rigidbodies, constraining them to move like they are connected by a spring. 弹簧关节是两个刚体组。制约它们就像弹簧一样。
Properties 属性
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 提示
页面最后更新: 2011-01-12 |
|