Unity Rigidbody2D 刚体类型选择 body type

简单的说 2D刚体都有三中 Bodytype 分别是dynamic  kinematic  static  即动态,运动,静态。

动态是需要运动、需要与其他所有刚体相互作用的类型。收重力和力的影响。

运动类型是被用于需要运动的物体,但是这种运动是模拟运动,其运动行为是被我们开发者完全限定的,不收重力和力的影响。可以碰撞。使用Rigidbody2D.MovePosition or Rigidbody2D.MoveRotation改变位置。

静态类型就是铁憨憨,它一直不会动的。它只与动态类型刚体碰撞,然而他还是不会动。:)

There are three options for Body Type; each defines a common and fixed behavior. Any Collider 2D attached to a Rigidbody 2D inherits the Rigidbody 2D’s Body Type. The three options are:

  • Dynamic
  • Kinematic
  • Static

The option you choose defines:

  • Movement (position & rotation) behavior
  • Collider interaction

Note that although Rigidbody 2Ds are often described as colliding with each other, it is the Collider 2Ds attached to each of those bodies which collide. Rigidbody 2Ds cannot collide with each other without colliders.

Changing the Body Type of a Rigidbody 2D can be a tricky process. When a Body Type changes, various mass-related internal properties are recalculated immediately, and all existing contacts for the Collider 2Ds attached to the Rigidbody 2D need to be re-evaluated during the GameObject’s next FixedUpdate. Depending on how many contacts and Collider 2Ds are attached to the body, changing the Body Type can cause variations in performance.

扫描二维码关注公众号,回复: 4943130 查看本文章

Body Type: Dynamic

Dynamic Rigidbody 2D is designed to move under simulation. It has the full set of properties available to it such as finite mass and drag, and is affected by gravity and forces. A Dynamic body will collide 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 common body type for things that need to move. It’s also the most performance-expensive body type, because of its dynamic nature and interactivity with everything around it. All Rigidbody 2D properties are available with this body type.

Body Type: Kinematic

Kinematic Rigidbody 2D is designed to move under simulation, but only under very explicit user control. While a Dynamic Rigidbody 2D is affected by gravity and forces, a Kinematic Rigidbody 2D isn’t. For this reason, it is fast and has a lower demand on system resources than a Dynamic Rigidbody 2D. Kinematic Rigidbody 2D is designed to be repositioned explicitly via Rigidbody2D.MovePosition or Rigidbody2D.MoveRotation. Use physics queries to detect collisions, and scripts to decide where and how the Rigidbody 2D should move.

Body Type: Static

Static Rigidbody 2D is designed to not move under simulation at all; if anything collides with it, a Static Rigidbody 2D behaves like an immovable object (as though it has infinite mass). It is also the least resource-intensive body type to use. A Static body only collides with Dynamic Rigidbody 2Ds. Having two Static Rigidbody 2Ds collide is not supported, since they are not designed to move.

猜你喜欢

转载自blog.csdn.net/qq_14812585/article/details/86506291