Physics Components 物理组件

优质
小牛编辑
135浏览
2023-12-01

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.

要使对象受物理引擎控制,简单的办法就是给它加个 Rigidbody 。当你这么干了,对象就会受到重力影响,而且会和世界中的其他对象碰撞。

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.

如果你直接移动一个非运动学刚体的Transform,它和其他对象的碰撞可能出问题。正确地方法应该是通过施加力或者扭矩来移动刚体。也可以添加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个Wheel Colliders和一段能够通过用户输入施加力给轮子的脚本。

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属性的刚体。运动学刚体不受力、重力或扭矩的影响。可以通过设置Transform 的position和rotation来准确的操作它们或者让它们动起来,但是,它们可以和其他的非运动学刚体互相作用。

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.

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

Component Details 组件细节

Physics Control 物理控制

  • Rigidbody - Rigidbodies put objects under physics control.
    刚体——刚体令对象出于物理作用控制下
  • Constant Force - A utility component that adds a constant force to a rigidbody. Great for rockets and other quick functionality.
    恒力——一个给刚体添加恒定的力的通用组件,适用于火箭和其他快速移动的功能。

Colliders 碰撞器

  • Sphere Collider - use for sphere-shaped objects.
    球形碰撞器——用于球形的对象
  • Box Collider - use for box-shaped objects.
    盒碰撞器——用于盒子形状的对象
  • Capsule Collider - use for capsule-like (a cylinder with hemisphere ends) objects.
    胶囊碰撞器——用于胶囊状(一个圆筒和两个半球端)对象
  • Mesh Collider - takes the graphical mesh and uses it as a collision shape.
    网格碰撞器——描绘网格并且产生碰撞效果
  • Physic Material - contains settings allowing you to fine-tune your object's physical properties (friction, bounce, etc).
    物理材质——包括允许你调整对象的物理属性至合适的设置(摩擦力,弹力等)

Joints 关节

  • Hinge Joint - Used to make door hinges.
    铰链关节——用于制作门铰链
  • Spring Joint - A spring-like joint.
    弹簧关节——像弹簧一样的关节
  • Fixed Joint - Use to "lock" objects together.
    固定关节——用于把对象锁到一起
  • Configurable Joint - Use create complex joint behaviors of virtually any kind
    可配置关节——用于创建实际上的任何种类的复杂关节行为

Special Function 特殊函数

  • Character Controller and Character Joint - Used to make character controllers.
    角色控制器和角色关节——用于制作角色控制部件。
  • Wheel Collider - A special collider for grounded vehicles.
    轮碰撞器——用于地上行驶的车辆的特殊碰撞器
  • Skinned Cloth - Used to create Skinned cloth
    蒙皮布料——用于创建皮肤布料
  • Interactive Cloth - Used to create Interactive cloths, this is just normal cloth being simulated.
    交互布料——用于创建可交互的布料,模拟通常的布料。

页面最后更新: 2010-05-05