用于 2D 精灵的刚体物理组件。
Rigidbody2D 类提供与 Rigidbody 类基本相同的功能,两者的区别在于:Rigidbody2D 用于 2D 环境,Rigidbody 用于 3D 环境。向精灵添加 Rigidbody2D 组件后,其运动将受到物理引擎的控制。这意味着精灵将受到重力的影响,并且可以在脚本中使用力对其进行控制。通过添加适当的碰撞体组件,精灵还能响应与其他精灵的碰撞。这种行为完全来自 Unity 的物理系统;您只需提供极少量的代码,就能实现令人印象深刻和逼真的物理行为,并提供没有显式编码到游戏中的“自发的”游戏玩法。
另请参阅:Rigidbody 类、SpriteRenderer 类、Collider2D 类、Joint2D 类。
angularDrag | 角阻力系数。 |
angularVelocity | 角速度(以度/秒为单位)。 |
attachedColliderCount | 返回附加到该 Rigidbody2D 的 Collider2D 的数量。 |
bodyType | Rigidbody2D 的物理行为类型。 |
centerOfMass | 刚体在本地空间中的质心。 |
collisionDetectionMode | 物理引擎用于检查两个对象是否发生碰撞的方法。 |
constraints | 控制该 Rigidbody2D 的模拟自由度。 |
drag | 阻力系数。 |
freezeRotation | 控制物理是否会更改对象的旋转。 |
gravityScale | 该对象受重力影响的程度。 |
inertia | The Rigidbody's resistance to changes in angular velocity (rotation). |
interpolation | 在更新之间使用的物理插值。 |
isKinematic | 该刚体是否应该脱离物理控制? |
mass | 刚体的质量。 |
position | 刚体的位置。 |
rotation | 刚体的旋转。 |
sharedMaterial | 应用于附加到该 Rigidbody2D 的所有 Collider2D 的 PhysicsMaterial2D。 |
simulated | 指示物理系统是否应模拟刚体。 |
sleepMode | 刚体最初处于的睡眠状态。 |
useAutoMass | 是否应根据附加碰撞体的 [[Collider2D.density]] 自动计算总刚体 mass? |
useFullKinematicContacts | 是否允许运动/运动和运动/静态碰撞? |
velocity | 刚体的线性速度,采用单位/秒形式。 |
worldCenterOfMass | 获取刚体在全局空间中的质心。 |
AddForce | 对刚体施加力。 |
AddForceAtPosition | 在空间中的给定位置施加力。 |
AddRelativeForce | 向 rigidbody2D 添加力(相对于其坐标系)。 |
AddTorque | 在刚体的质心处施加扭矩。 |
Cast | 附加到 Rigidbody2D 的所有 Collider2D 形状都将投射到场景中 - 从每个碰撞体的位置开始,忽略附加到同一个 Rigidbody2D 的碰撞体。 |
ClosestPoint | 返回附加到此刚体的所有已启用碰撞体周边上最接近指定 position 的点。 |
Distance | 计算 collider 到附加到该 Rigidbody2D 的所有 Collider2D 的最小距离。 |
GetAttachedColliders | 返回附加到该 Rigidbody2D 的所有 Collider2D。 |
GetContacts | 获取附加到该刚体的所有碰撞体的所有接触点。 |
GetPoint | 根据位于刚体全局空间中的点 /point/,获取本地空间点。 |
GetPointVelocity | 点 /Point/(全局空间)处刚体的速度。 |
GetRelativePoint | 根据位于刚体本地空间中的点 /relativePoint/,获取全局空间点。 |
GetRelativePointVelocity | 点 /Point/(本地空间)处刚体的速度。 |
GetRelativeVector | 根据位于刚体本地空间中的向量 /relativeVector/,获取全局空间向量。 |
GetVector | 根据位于刚体全局空间中的向量 /vector/,获取本地空间向量。 |
IsAwake | 刚体是否处于“唤醒”状态? |
IsSleeping | 刚体是否处于“睡眠”状态? |
IsTouching | 检查 collider 是否正在接触附加到该刚体的任何碰撞体。 |
IsTouchingLayers | 检查附加到该刚体的任何碰撞体是否正在接触指定 layerMask 上的任何碰撞体。 |
MovePosition | 将刚体移动到 /position/。 |
MoveRotation | 将刚体旋转到 /angle/(以度为单位)。 |
OverlapCollider | 获取与附加到该 Rigidbody2D 的所有碰撞体重叠的所有碰撞体的列表。 |
OverlapPoint | 检查是否有任何 Rigidbody2D 碰撞体与空间中的某个点重叠。 |
SetRotation | 将 Rigidbody2D 的旋转设置为 /angle/(以度为单位)。 |
Sleep | 使刚体进入“睡眠”状态。 |
WakeUp | 禁用刚体的“睡眠”状态。 |
gameObject | 此组件附加到的游戏对象。始终将组件附加到游戏对象。 |
tag | 此游戏对象的标签。 |
transform | 附加到此 GameObject 的 Transform。 |
hideFlags | 该对象应该隐藏、随场景一起保存还是由用户修改? |
name | 对象的名称。 |
BroadcastMessage | 调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。 |
CompareTag | 此游戏对象是否使用 tag 进行了标记? |
GetComponent | Returns the component of Type type if the GameObject has one attached, null if it doesn't. Will also return disabled components. |
GetComponentInChildren | 使用深度首次搜索返回 GameObject 或其任何子项中类型为 type 的组件。 |
GetComponentInParent | 返回 GameObject 或其任何父项中类型为 type 的组件。 |
GetComponents | 返回 GameObject 中类型为 type 的所有组件。 |
GetComponentsInChildren | Returns all components of Type type in the GameObject or any of its children. Works recursively. |
GetComponentsInParent | 返回 GameObject 或其任何父项中类型为 type 的所有组件。 |
SendMessage | 调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。 |
SendMessageUpwards | 调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。 |
TryGetComponent | 获取指定类型的组件(如果存在)。 |
GetInstanceID | 返回对象的实例 ID。 |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindObjectOfType | 返回第一个类型为 type 的已加载的激活对象。 |
FindObjectsOfType | Gets a list of all loaded objects of Type type. |
Instantiate | 克隆 original 对象并返回克隆对象。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.