您的位置:首页 > 移动开发 > Unity3D

【API】Unity5.6 Rigidbody 2D

2017-07-12 09:48 477 查看

Rigidbody 2D

SWITCH
TO SCRIPTING
A Rigidbody 2D component places an objectunder the control of the physics engine. Many concepts familiar from thestandard Rigidbody componentcarry
over to Rigidbody 2D; the differences are that in 2D, objects can onlymove in the XY plane and can only rotate on an axis perpendicular to thatplane.
一个2D刚体组件面板,它的底层是由物理引擎控制着。有许多熟悉的刚体组件支撑着2D刚体,他们的不同点只在于2D,该物体只能在X,Y轴上移动,垂直于平面旋转。

TheRigidbody 2D component. This appears differently in the Unity Editor dependingon which Body Type you have selected. See Body
Type, below, to learn more.
2D刚体选项如图



How a Rigidbody 2D works/2D刚体如何工作

Usually, the Unity Editor’s Transformcomponent defines how a GameObject (and its child GameObjects) is positioned,rotated and scaled within the Scene. When it is changed, it updates othercomponents,
which may update things like where they render or where collidersare positioned. The 2D physics engine is able to move colliders and make theminteract with each other, so a method is required for the physics engine tocommunicate this movement of colliders
back to the Transform components. Thismovement and connection with colliders is what a Rigidbody 2D component is for.
通常,Unity编辑器的变换组件定义了一个游戏对象(及其子对象)的位置,旋转和缩放在一个场景内。当它改变时,它更新的其他成分,可更新的东西像他们渲染或碰撞的位置。2D物理引擎能够使各个物体移动碰撞并相互作用,所以一种说法是物理引擎是物体运动碰撞回变换所需的组件。运动与碰撞就由2D刚体组件来实现的。
The Rigidbody 2D component overrides theTransform and updates it to a position/rotation defined by the Rigidbody 2D.Note that while you can still override the Rigidbody 2D by modifying
theTransform component yourself (because Unity exposes all properties on allcomponents), doing so will cause problems such as GameObjects passing throughor into each other, and unpredictable movement.
2D刚体组件发挥了2D物理引擎效果来影响物体的更改新增位置或旋转。注意,你也可以通过(因为Unity3D公开了所有组件的属性)修改组件属性影响2D刚体,这样会导致游戏对象发生改变和不可预知的运动。
Any Collider 2D component added to the sameGameObject or child GameObject is implicitly attached to that Rigidbody 2D.When a Collider 2D is attached to the Rigidbody 2D, it moves with
it. ACollider 2D should never be moved directly using the Transform or any collideroffset; the Rigidbody 2D should be moved instead. This offers the bestperformance and ensures correct collision detection. Collider 2Ds attached tothe same Rigidbody 2D won’t
collide with each other. This means you can createa set of colliders that act effectively as a single compound collider, allmoving and rotating in sync with the Rigidbody 2D.
任何2D碰撞组件添加到游戏物体或者子游戏物体时都隐式的关联上2D刚体,当2D碰撞关联上2D刚体,当运动时,一个2D碰撞是无法运动的,它无法直接改变位置或者任何碰撞偏移即无法直接使用,而2D刚体正好可以担任这项功能。这提供了最好的性能和确保正确的碰撞检测。2D碰撞机关联同一2D刚体是无法互相作用的,这意味着你可以创造一套碰撞效果,有效的选择选项,碰撞机与游戏物体一对一映射,他们的所有运动都由2D刚体实现。
When designing a Scene, you are free to use adefault Rigidbody 2D and start attaching colliders. These colliders allow anyother colliders attached to different Rigidbody 2Ds to collide
with each other.
当设计一个场景,你可以使用一个默认的2D刚体开始碰撞实现,这些碰撞机可以与拥有2D刚体的物体互相碰撞

Tip/提示

Adding a Rigidbody 2D allows a sprite to move in aphysically convincing way by applying forces from the scripting API. When theappropriate collider component is
also attached to the sprite GameObject, it isaffected by collisions with other moving GameObjects. Using physics simplifiesmany common gameplay mechanics and allows for realistic behavior with minimalcoding.
添加一个2D刚体允许精灵在真实的移动应用的力量从API中。当适当的对撞机组件也连接到精灵的物体,它是通过与其他移动物体的碰撞的影响。使用物理简化了许多常见的游戏机制,并允许以最小的编码实现真实的行为。

Body Type

The Rigidbody 2D component has a setting atthe top labelled Body Type. The optionyou choose for this affects the other settings available on the component.
2D刚体组件顶部有标记类型设置,你选择的选项会影响组件上可用的其他设置

There are three options for BodyType; each defines a common and fixed behavior. Any Collider 2Dattached to a Rigidbody 2D inherits the Rigidbody 2D’s BodyType.
The three options are:
体型选项有三种,每个定义一个固定的刚体特性,任何2D碰撞机附加到2D刚体都会继承2D刚体的体型选择,这三种选择是:
·        Dynamic/动态
·        Kinematic/运动
·        Static/静态
The option you choose defines:
你可以选择好后的选项:
·        Movement (position &rotation) behavior
运动(位置和选择)行为
·        Collider interaction
对撞机互动
Note that although Rigidbody 2Ds are oftendescribed as colliding with each other, it is the Collider 2Ds attached to eachof those bodies which collide. Rigidbody 2Ds cannot collide with
each otherwithout colliders.
注意,尽管2D刚体经常被描述与其他物体碰撞,这是因为有附加了2D碰撞组件来与其他碰撞机碰撞,2D刚体在没有碰撞机时无法与其他刚体碰撞。
Changing the Body Type of a Rigidbody 2D canbe a tricky process. When a Body Type changes, various mass-related internalproperties are recalculated immediately, and all existing contacts
for theCollider 2Ds attached to the Rigidbody 2D need to be re-evaluated during theGameObject’s next FixedUpdate.
Depending on how many contactsand Collider 2Ds are attached to the body, changing the Body Type can causevariations in performance.
改变一个2D刚体类型可以是说一个关键的过程。当一个体型的变化,各种质量相关的内部属性会立即重新计算,和所有现在附加了对撞机的2D刚体都需要重新计算或者更新修复数据。这取决于有多少的接触和2D碰撞是依附于刚体上,改变2D刚体的类型可以导致在性能上发生变化。

Body Type: Dynamic

Dynamic Rigidbody 2D is designed to move undersimulation. It has the full set of properties available to it such as finitemass and drag, and is affected by gravity
and forces. A Dynamic body willcollide with every other body type, and is the most interactive of body types.This is the default body type for a Rigidbody 2D, because it is the most commonbody type for things that need to move. It’s also the mostperformance-expensive
body type, because of its dynamic nature andinteractivity with everything around it. All Rigidbody 2D properties areavailable with this body type.
动态2D刚体是用来仿真运动的,它有全套的属性,如有限的质量和阻力,受重力和施加力的影响。一个动态刚体会与其他类型刚体发生碰撞,是刚体类型最具互动性的,这是一个2D刚体默认类型,因为大部分物品会进行运动,这需要动态刚体来实现。它是花费最多性能的刚体,因为它具有动态性和与周围事物的互动性。所有的2D刚体类型里的性能选项都能在在动态刚体中找到
Do not use the Transform component to set theposition or rotation of a Dynamic Rigidbody 2D. The simulationrepositions a Dynamic Rigidbody 2D
according to itsvelocity; you can change this directly via forces applied to it by scripts, orindirectly via collisions and gravity.
不用使用直接变化组件去设置动态刚体的位置或者旋转。动态刚体模拟运动是根据它的速度,你可以使用脚本改变施加力来控制,如或者间接通过碰撞或者重力。
Property:

Function:

Body Type

刚体类型

Set the RigidBody 2D’s component settings, so that you can manipulate movement (position and rotation) behavior and Collider 2D interaction. 

Options are: DynamicKinematicStatic

2D刚体组件内容设置。你可以根据需要设置运动(位置和旋转)的改变和碰撞机互动,选项有动态的,运动的,静态的

Material

材料

Use this to specify a common material for all Collider 2Ds attached to a specific parent Rigidbody 2D. 
Note: A Collider 2D uses its own Material property if it has one set. If there is no Material specified here or in the Collider 2D, the default option is None (Physics Material 2D). This uses a default Material which you can
set in the Physics 2D Settings window. 

A Collider 2D uses the following order of priority to determine which Material setting to use: 

1. A Physics Material 2D specified on the Collider 2D itself.

2. A Physics Material 2D specified on the attached Rigidbody 2D.

A Physics Material 2D default material specified in the Physics 2D Settings.
TIP: Use this to ensure that all Collider 2Ds attached to the same Static Body Type Rigidbody 2D can all use the same Material.

用这个来指定所选的2D碰撞机关联到2D刚体上的常用材料

注意:一个2D碰撞机自己使用材料是一种设置方法,如果2D刚体和2D碰撞机都没有设置,则默认选项为无,即一个默认材质,你可以在2D物理窗口设置,2D碰撞机使用材料优先确定列表:

(1).2D碰撞机指定的物理材料,(2).2D刚体指定的物理材料,(3).在2D物理设置界面上指定的为默认材料

提示:使用这个来确保所有2D对撞关联的2D静态刚体使用相同的材料

Simulated

模拟

Enable Simulated (check the box) if you want the Rigidbody 2D and any attached Collider 2Ds and Joint 2Ds to interact with the physics simulation during run time. If this is disabled (the box is unchecked),
these components do not interact with the simulation. See Rigidbody
2D properties: Simulated, below, for more details. This box is checked by default.

选中模拟选项,2D刚体将会与任何附加了2D碰撞机和2D关节发生仿真物理效果,如果禁用,则这些组件不与发生仿真物理效果,下面的更多细节会与该选项关联

Use Auto Mass

使用自动质量

Check the box if you want the Rigidbody 2D to automatically detect the GameObject’s mass from its Collider 2D.

如果你想2D刚体从对撞中检查物体质量。

Mass

质量

Define the mass of the Rigidbody 2D. This is grayed out if you have selected Use Auto Mass.

定义2D刚体质量。如果你选中了使用自动质量,这个选项为灰色的

Linear Drag

线性阻力

Drag coefficient affecting positional movement.

影响位置运动的阻力系数。

Angular Drag

角度阻力

Drag coefficient affecting rotational movement.

影响旋转运动的阻力系数。

Gravity Scale

重力标度

Define the degree to which the GameObject is affected by gravity.

明确物体受到重力的程度

Collision Detection

碰撞检测

Define how collisions between Collider 2D are detected.

定义2D碰撞器之间是如何检测碰撞的

        Discrete

分离的
When you set the Collision Detection to Discrete, GameObjects with Rigidbody 2Ds and Collider 2Ds can overlap or pass through each other during a physics update, if they are moving
fast enough. Collision contacts are only generated at the new position.

当你设置碰撞检测为分离时,游戏物体上的2D刚体和2D碰撞在发生作用时可以重叠或者穿过其他物体时做一次物理效果更新。如果他们移动的足够快的话,碰撞会关联一次在一个新的位置。当2D刚体移动,仅在新位置碰撞被检测。

        Continuous

连续的
When the Collision Detection is set to Continuous, GameObjects with Rigidbody 2Ds and Collider 2Ds do not pass through each other during an update. Instead, Unity calculates the first
impact point of any of the Collider 2Ds, and moves the GameObject there. Note that this takes more CPU time than Discrete.

当碰撞检测设置为连续,游戏物体的2D刚体2D碰撞没发生重叠或者穿过的时候都会更新检测,相反,U3D会计算任何一次2D碰撞即碰撞点,物体移动就有检测。注意,这比分离检测使用更多的CPU性能。确保所有2D刚体移动时检测到碰撞。

Sleeping Mode

睡眠模式

Define how the GameObject “sleeps” to save processor time when it is at rest.

如何定义游戏物体在睡眠去保存处理时间。

        Never Sleep

没有睡眠

Sleeping is disabled (this should be avoided where possible, as it can impact system resources).

睡眠被禁用(在可能的情况下应该避免它。因为它会影响系统资源)

        Start Awake

开始清醒

GameObject is initially awake.

游戏开始就是清醒的。

        Start Asleep

开始睡眠

GameObject is initially asleep but can be woken by collisions.

游戏开始是睡眠的,但可以被碰撞。

Interpolate

插值

Define how the GameObject’s movement is interpolated between physics updates (useful when motion tends to be jerky).

如何定义游戏对面运动插值之间在物理更新(有用的时间去)

        None



No movement smoothing is applied.

没有移动平滑应用

        Interpolate

插值

Movement is smoothed based on the GameObject’s positions in previous frames.

运动平滑基于先去帧中对象的位置

        Extrapolate

推算

Movement is smoothed based on an estimate of its position in the next frame.

基于下一帧中位置来推算平滑运动

Constraints

限制

Define any restrictions on the Rigidbody 2D’s motion

定义2D刚体的一些限制.

Freeze Position

冻结位置

Stops the Rigidbody 2D moving in the world X & Y axes selectively.

停止2D刚体在世界上的X和Y轴的运动。

Freeze Rotation

冻结旋转

Stops the Rigidbody 2D rotating around the Z axes selectively.

停止2D刚体围绕Z轴的旋转。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3dd Rigidbody 2D