class_rigidbody2d.rst 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/RigidBody2D.xml.
  6. .. _class_RigidBody2D:
  7. RigidBody2D
  8. ===========
  9. **Inherits:** :ref:`PhysicsBody2D<class_PhysicsBody2D>` **<** :ref:`CollisionObject2D<class_CollisionObject2D>` **<** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`PhysicalBone2D<class_PhysicalBone2D>`
  11. A 2D physics body that is moved by a physics simulation.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. **RigidBody2D** implements full 2D physics. It cannot be controlled directly, instead, you must apply forces to it (gravity, impulses, etc.), and the physics simulation will calculate the resulting movement, rotation, react to collisions, and affect other physics bodies in its path.
  16. The body's behavior can be adjusted via :ref:`lock_rotation<class_RigidBody2D_property_lock_rotation>`, :ref:`freeze<class_RigidBody2D_property_freeze>`, and :ref:`freeze_mode<class_RigidBody2D_property_freeze_mode>`. By changing various properties of the object, such as :ref:`mass<class_RigidBody2D_property_mass>`, you can control how the physics simulation acts on it.
  17. A rigid body will always maintain its shape and size, even when forces are applied to it. It is useful for objects that can be interacted with in an environment, such as a tree that can be knocked over or a stack of crates that can be pushed around.
  18. If you need to override the default physics behavior, you can write a custom force integration function. See :ref:`custom_integrator<class_RigidBody2D_property_custom_integrator>`.
  19. \ **Note:** Changing the 2D transform or :ref:`linear_velocity<class_RigidBody2D_property_linear_velocity>` of a **RigidBody2D** very often may lead to some unpredictable behaviors. If you need to directly affect the body, prefer :ref:`_integrate_forces<class_RigidBody2D_private_method__integrate_forces>` as it allows you to directly access the physics state.
  20. .. rst-class:: classref-introduction-group
  21. Tutorials
  22. ---------
  23. - `2D Physics Platformer Demo <https://godotengine.org/asset-library/asset/2725>`__
  24. - `Instancing Demo <https://godotengine.org/asset-library/asset/2716>`__
  25. .. rst-class:: classref-reftable-group
  26. Properties
  27. ----------
  28. .. table::
  29. :widths: auto
  30. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  31. | :ref:`float<class_float>` | :ref:`angular_damp<class_RigidBody2D_property_angular_damp>` | ``0.0`` |
  32. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  33. | :ref:`DampMode<enum_RigidBody2D_DampMode>` | :ref:`angular_damp_mode<class_RigidBody2D_property_angular_damp_mode>` | ``0`` |
  34. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  35. | :ref:`float<class_float>` | :ref:`angular_velocity<class_RigidBody2D_property_angular_velocity>` | ``0.0`` |
  36. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  37. | :ref:`bool<class_bool>` | :ref:`can_sleep<class_RigidBody2D_property_can_sleep>` | ``true`` |
  38. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  39. | :ref:`Vector2<class_Vector2>` | :ref:`center_of_mass<class_RigidBody2D_property_center_of_mass>` | ``Vector2(0, 0)`` |
  40. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  41. | :ref:`CenterOfMassMode<enum_RigidBody2D_CenterOfMassMode>` | :ref:`center_of_mass_mode<class_RigidBody2D_property_center_of_mass_mode>` | ``0`` |
  42. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  43. | :ref:`Vector2<class_Vector2>` | :ref:`constant_force<class_RigidBody2D_property_constant_force>` | ``Vector2(0, 0)`` |
  44. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  45. | :ref:`float<class_float>` | :ref:`constant_torque<class_RigidBody2D_property_constant_torque>` | ``0.0`` |
  46. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  47. | :ref:`bool<class_bool>` | :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` | ``false`` |
  48. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  49. | :ref:`CCDMode<enum_RigidBody2D_CCDMode>` | :ref:`continuous_cd<class_RigidBody2D_property_continuous_cd>` | ``0`` |
  50. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  51. | :ref:`bool<class_bool>` | :ref:`custom_integrator<class_RigidBody2D_property_custom_integrator>` | ``false`` |
  52. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  53. | :ref:`bool<class_bool>` | :ref:`freeze<class_RigidBody2D_property_freeze>` | ``false`` |
  54. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  55. | :ref:`FreezeMode<enum_RigidBody2D_FreezeMode>` | :ref:`freeze_mode<class_RigidBody2D_property_freeze_mode>` | ``0`` |
  56. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  57. | :ref:`float<class_float>` | :ref:`gravity_scale<class_RigidBody2D_property_gravity_scale>` | ``1.0`` |
  58. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  59. | :ref:`float<class_float>` | :ref:`inertia<class_RigidBody2D_property_inertia>` | ``0.0`` |
  60. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  61. | :ref:`float<class_float>` | :ref:`linear_damp<class_RigidBody2D_property_linear_damp>` | ``0.0`` |
  62. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  63. | :ref:`DampMode<enum_RigidBody2D_DampMode>` | :ref:`linear_damp_mode<class_RigidBody2D_property_linear_damp_mode>` | ``0`` |
  64. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  65. | :ref:`Vector2<class_Vector2>` | :ref:`linear_velocity<class_RigidBody2D_property_linear_velocity>` | ``Vector2(0, 0)`` |
  66. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  67. | :ref:`bool<class_bool>` | :ref:`lock_rotation<class_RigidBody2D_property_lock_rotation>` | ``false`` |
  68. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  69. | :ref:`float<class_float>` | :ref:`mass<class_RigidBody2D_property_mass>` | ``1.0`` |
  70. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  71. | :ref:`int<class_int>` | :ref:`max_contacts_reported<class_RigidBody2D_property_max_contacts_reported>` | ``0`` |
  72. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  73. | :ref:`PhysicsMaterial<class_PhysicsMaterial>` | :ref:`physics_material_override<class_RigidBody2D_property_physics_material_override>` | |
  74. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  75. | :ref:`bool<class_bool>` | :ref:`sleeping<class_RigidBody2D_property_sleeping>` | ``false`` |
  76. +------------------------------------------------------------+----------------------------------------------------------------------------------------+-------------------+
  77. .. rst-class:: classref-reftable-group
  78. Methods
  79. -------
  80. .. table::
  81. :widths: auto
  82. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | |void| | :ref:`_integrate_forces<class_RigidBody2D_private_method__integrate_forces>`\ (\ state\: :ref:`PhysicsDirectBodyState2D<class_PhysicsDirectBodyState2D>`\ ) |virtual| |
  84. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | |void| | :ref:`add_constant_central_force<class_RigidBody2D_method_add_constant_central_force>`\ (\ force\: :ref:`Vector2<class_Vector2>`\ ) |
  86. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | |void| | :ref:`add_constant_force<class_RigidBody2D_method_add_constant_force>`\ (\ force\: :ref:`Vector2<class_Vector2>`, position\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) |
  88. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | |void| | :ref:`add_constant_torque<class_RigidBody2D_method_add_constant_torque>`\ (\ torque\: :ref:`float<class_float>`\ ) |
  90. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | |void| | :ref:`apply_central_force<class_RigidBody2D_method_apply_central_force>`\ (\ force\: :ref:`Vector2<class_Vector2>`\ ) |
  92. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | |void| | :ref:`apply_central_impulse<class_RigidBody2D_method_apply_central_impulse>`\ (\ impulse\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) |
  94. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | |void| | :ref:`apply_force<class_RigidBody2D_method_apply_force>`\ (\ force\: :ref:`Vector2<class_Vector2>`, position\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) |
  96. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | |void| | :ref:`apply_impulse<class_RigidBody2D_method_apply_impulse>`\ (\ impulse\: :ref:`Vector2<class_Vector2>`, position\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) |
  98. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | |void| | :ref:`apply_torque<class_RigidBody2D_method_apply_torque>`\ (\ torque\: :ref:`float<class_float>`\ ) |
  100. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | |void| | :ref:`apply_torque_impulse<class_RigidBody2D_method_apply_torque_impulse>`\ (\ torque\: :ref:`float<class_float>`\ ) |
  102. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`Array<class_Array>`\[:ref:`Node2D<class_Node2D>`\] | :ref:`get_colliding_bodies<class_RigidBody2D_method_get_colliding_bodies>`\ (\ ) |const| |
  104. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`int<class_int>` | :ref:`get_contact_count<class_RigidBody2D_method_get_contact_count>`\ (\ ) |const| |
  106. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | |void| | :ref:`set_axis_velocity<class_RigidBody2D_method_set_axis_velocity>`\ (\ axis_velocity\: :ref:`Vector2<class_Vector2>`\ ) |
  108. +----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. .. rst-class:: classref-section-separator
  110. ----
  111. .. rst-class:: classref-descriptions-group
  112. Signals
  113. -------
  114. .. _class_RigidBody2D_signal_body_entered:
  115. .. rst-class:: classref-signal
  116. **body_entered**\ (\ body\: :ref:`Node<class_Node>`\ ) :ref:`🔗<class_RigidBody2D_signal_body_entered>`
  117. Emitted when a collision with another :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>` occurs. Requires :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`max_contacts_reported<class_RigidBody2D_property_max_contacts_reported>` to be set high enough to detect all the collisions. :ref:`TileMap<class_TileMap>`\ s are detected if the :ref:`TileSet<class_TileSet>` has Collision :ref:`Shape2D<class_Shape2D>`\ s.
  118. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_RigidBody2D_signal_body_exited:
  122. .. rst-class:: classref-signal
  123. **body_exited**\ (\ body\: :ref:`Node<class_Node>`\ ) :ref:`🔗<class_RigidBody2D_signal_body_exited>`
  124. Emitted when the collision with another :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>` ends. Requires :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`max_contacts_reported<class_RigidBody2D_property_max_contacts_reported>` to be set high enough to detect all the collisions. :ref:`TileMap<class_TileMap>`\ s are detected if the :ref:`TileSet<class_TileSet>` has Collision :ref:`Shape2D<class_Shape2D>`\ s.
  125. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_RigidBody2D_signal_body_shape_entered:
  129. .. rst-class:: classref-signal
  130. **body_shape_entered**\ (\ body_rid\: :ref:`RID<class_RID>`, body\: :ref:`Node<class_Node>`, body_shape_index\: :ref:`int<class_int>`, local_shape_index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_RigidBody2D_signal_body_shape_entered>`
  131. Emitted when one of this RigidBody2D's :ref:`Shape2D<class_Shape2D>`\ s collides with another :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`'s :ref:`Shape2D<class_Shape2D>`\ s. Requires :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`max_contacts_reported<class_RigidBody2D_property_max_contacts_reported>` to be set high enough to detect all the collisions. :ref:`TileMap<class_TileMap>`\ s are detected if the :ref:`TileSet<class_TileSet>` has Collision :ref:`Shape2D<class_Shape2D>`\ s.
  132. \ ``body_rid`` the :ref:`RID<class_RID>` of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileSet<class_TileSet>`'s :ref:`CollisionObject2D<class_CollisionObject2D>` used by the :ref:`PhysicsServer2D<class_PhysicsServer2D>`.
  133. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  134. \ ``body_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>` used by the :ref:`PhysicsServer2D<class_PhysicsServer2D>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``body.shape_owner_get_owner(body.shape_find_owner(body_shape_index))``.
  135. \ ``local_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of this RigidBody2D used by the :ref:`PhysicsServer2D<class_PhysicsServer2D>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``self.shape_owner_get_owner(self.shape_find_owner(local_shape_index))``.
  136. .. rst-class:: classref-item-separator
  137. ----
  138. .. _class_RigidBody2D_signal_body_shape_exited:
  139. .. rst-class:: classref-signal
  140. **body_shape_exited**\ (\ body_rid\: :ref:`RID<class_RID>`, body\: :ref:`Node<class_Node>`, body_shape_index\: :ref:`int<class_int>`, local_shape_index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_RigidBody2D_signal_body_shape_exited>`
  141. Emitted when the collision between one of this RigidBody2D's :ref:`Shape2D<class_Shape2D>`\ s and another :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`'s :ref:`Shape2D<class_Shape2D>`\ s ends. Requires :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`max_contacts_reported<class_RigidBody2D_property_max_contacts_reported>` to be set high enough to detect all the collisions. :ref:`TileMap<class_TileMap>`\ s are detected if the :ref:`TileSet<class_TileSet>` has Collision :ref:`Shape2D<class_Shape2D>`\ s.
  142. \ ``body_rid`` the :ref:`RID<class_RID>` of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileSet<class_TileSet>`'s :ref:`CollisionObject2D<class_CollisionObject2D>` used by the :ref:`PhysicsServer2D<class_PhysicsServer2D>`.
  143. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  144. \ ``body_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>` used by the :ref:`PhysicsServer2D<class_PhysicsServer2D>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``body.shape_owner_get_owner(body.shape_find_owner(body_shape_index))``.
  145. \ ``local_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of this RigidBody2D used by the :ref:`PhysicsServer2D<class_PhysicsServer2D>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``self.shape_owner_get_owner(self.shape_find_owner(local_shape_index))``.
  146. .. rst-class:: classref-item-separator
  147. ----
  148. .. _class_RigidBody2D_signal_sleeping_state_changed:
  149. .. rst-class:: classref-signal
  150. **sleeping_state_changed**\ (\ ) :ref:`🔗<class_RigidBody2D_signal_sleeping_state_changed>`
  151. Emitted when the physics engine changes the body's sleeping state.
  152. \ **Note:** Changing the value :ref:`sleeping<class_RigidBody2D_property_sleeping>` will not trigger this signal. It is only emitted if the sleeping state is changed by the physics engine or ``emit_signal("sleeping_state_changed")`` is used.
  153. .. rst-class:: classref-section-separator
  154. ----
  155. .. rst-class:: classref-descriptions-group
  156. Enumerations
  157. ------------
  158. .. _enum_RigidBody2D_FreezeMode:
  159. .. rst-class:: classref-enumeration
  160. enum **FreezeMode**: :ref:`🔗<enum_RigidBody2D_FreezeMode>`
  161. .. _class_RigidBody2D_constant_FREEZE_MODE_STATIC:
  162. .. rst-class:: classref-enumeration-constant
  163. :ref:`FreezeMode<enum_RigidBody2D_FreezeMode>` **FREEZE_MODE_STATIC** = ``0``
  164. Static body freeze mode (default). The body is not affected by gravity and forces. It can be only moved by user code and doesn't collide with other bodies along its path.
  165. .. _class_RigidBody2D_constant_FREEZE_MODE_KINEMATIC:
  166. .. rst-class:: classref-enumeration-constant
  167. :ref:`FreezeMode<enum_RigidBody2D_FreezeMode>` **FREEZE_MODE_KINEMATIC** = ``1``
  168. Kinematic body freeze mode. Similar to :ref:`FREEZE_MODE_STATIC<class_RigidBody2D_constant_FREEZE_MODE_STATIC>`, but collides with other bodies along its path when moved. Useful for a frozen body that needs to be animated.
  169. .. rst-class:: classref-item-separator
  170. ----
  171. .. _enum_RigidBody2D_CenterOfMassMode:
  172. .. rst-class:: classref-enumeration
  173. enum **CenterOfMassMode**: :ref:`🔗<enum_RigidBody2D_CenterOfMassMode>`
  174. .. _class_RigidBody2D_constant_CENTER_OF_MASS_MODE_AUTO:
  175. .. rst-class:: classref-enumeration-constant
  176. :ref:`CenterOfMassMode<enum_RigidBody2D_CenterOfMassMode>` **CENTER_OF_MASS_MODE_AUTO** = ``0``
  177. In this mode, the body's center of mass is calculated automatically based on its shapes. This assumes that the shapes' origins are also their center of mass.
  178. .. _class_RigidBody2D_constant_CENTER_OF_MASS_MODE_CUSTOM:
  179. .. rst-class:: classref-enumeration-constant
  180. :ref:`CenterOfMassMode<enum_RigidBody2D_CenterOfMassMode>` **CENTER_OF_MASS_MODE_CUSTOM** = ``1``
  181. In this mode, the body's center of mass is set through :ref:`center_of_mass<class_RigidBody2D_property_center_of_mass>`. Defaults to the body's origin position.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _enum_RigidBody2D_DampMode:
  185. .. rst-class:: classref-enumeration
  186. enum **DampMode**: :ref:`🔗<enum_RigidBody2D_DampMode>`
  187. .. _class_RigidBody2D_constant_DAMP_MODE_COMBINE:
  188. .. rst-class:: classref-enumeration-constant
  189. :ref:`DampMode<enum_RigidBody2D_DampMode>` **DAMP_MODE_COMBINE** = ``0``
  190. In this mode, the body's damping value is added to any value set in areas or the default value.
  191. .. _class_RigidBody2D_constant_DAMP_MODE_REPLACE:
  192. .. rst-class:: classref-enumeration-constant
  193. :ref:`DampMode<enum_RigidBody2D_DampMode>` **DAMP_MODE_REPLACE** = ``1``
  194. In this mode, the body's damping value replaces any value set in areas or the default value.
  195. .. rst-class:: classref-item-separator
  196. ----
  197. .. _enum_RigidBody2D_CCDMode:
  198. .. rst-class:: classref-enumeration
  199. enum **CCDMode**: :ref:`🔗<enum_RigidBody2D_CCDMode>`
  200. .. _class_RigidBody2D_constant_CCD_MODE_DISABLED:
  201. .. rst-class:: classref-enumeration-constant
  202. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_DISABLED** = ``0``
  203. Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
  204. .. _class_RigidBody2D_constant_CCD_MODE_CAST_RAY:
  205. .. rst-class:: classref-enumeration-constant
  206. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_CAST_RAY** = ``1``
  207. Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise.
  208. .. _class_RigidBody2D_constant_CCD_MODE_CAST_SHAPE:
  209. .. rst-class:: classref-enumeration-constant
  210. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_CAST_SHAPE** = ``2``
  211. Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise.
  212. .. rst-class:: classref-section-separator
  213. ----
  214. .. rst-class:: classref-descriptions-group
  215. Property Descriptions
  216. ---------------------
  217. .. _class_RigidBody2D_property_angular_damp:
  218. .. rst-class:: classref-property
  219. :ref:`float<class_float>` **angular_damp** = ``0.0`` :ref:`🔗<class_RigidBody2D_property_angular_damp>`
  220. .. rst-class:: classref-property-setget
  221. - |void| **set_angular_damp**\ (\ value\: :ref:`float<class_float>`\ )
  222. - :ref:`float<class_float>` **get_angular_damp**\ (\ )
  223. Damps the body's rotation. By default, the body will use the :ref:`ProjectSettings.physics/2d/default_angular_damp<class_ProjectSettings_property_physics/2d/default_angular_damp>` setting or any value override set by an :ref:`Area2D<class_Area2D>` the body is in. Depending on :ref:`angular_damp_mode<class_RigidBody2D_property_angular_damp_mode>`, you can set :ref:`angular_damp<class_RigidBody2D_property_angular_damp>` to be added to or to replace the body's damping value.
  224. See :ref:`ProjectSettings.physics/2d/default_angular_damp<class_ProjectSettings_property_physics/2d/default_angular_damp>` for more details about damping.
  225. .. rst-class:: classref-item-separator
  226. ----
  227. .. _class_RigidBody2D_property_angular_damp_mode:
  228. .. rst-class:: classref-property
  229. :ref:`DampMode<enum_RigidBody2D_DampMode>` **angular_damp_mode** = ``0`` :ref:`🔗<class_RigidBody2D_property_angular_damp_mode>`
  230. .. rst-class:: classref-property-setget
  231. - |void| **set_angular_damp_mode**\ (\ value\: :ref:`DampMode<enum_RigidBody2D_DampMode>`\ )
  232. - :ref:`DampMode<enum_RigidBody2D_DampMode>` **get_angular_damp_mode**\ (\ )
  233. Defines how :ref:`angular_damp<class_RigidBody2D_property_angular_damp>` is applied. See :ref:`DampMode<enum_RigidBody2D_DampMode>` for possible values.
  234. .. rst-class:: classref-item-separator
  235. ----
  236. .. _class_RigidBody2D_property_angular_velocity:
  237. .. rst-class:: classref-property
  238. :ref:`float<class_float>` **angular_velocity** = ``0.0`` :ref:`🔗<class_RigidBody2D_property_angular_velocity>`
  239. .. rst-class:: classref-property-setget
  240. - |void| **set_angular_velocity**\ (\ value\: :ref:`float<class_float>`\ )
  241. - :ref:`float<class_float>` **get_angular_velocity**\ (\ )
  242. The body's rotational velocity in *radians* per second.
  243. .. rst-class:: classref-item-separator
  244. ----
  245. .. _class_RigidBody2D_property_can_sleep:
  246. .. rst-class:: classref-property
  247. :ref:`bool<class_bool>` **can_sleep** = ``true`` :ref:`🔗<class_RigidBody2D_property_can_sleep>`
  248. .. rst-class:: classref-property-setget
  249. - |void| **set_can_sleep**\ (\ value\: :ref:`bool<class_bool>`\ )
  250. - :ref:`bool<class_bool>` **is_able_to_sleep**\ (\ )
  251. If ``true``, the body can enter sleep mode when there is no movement. See :ref:`sleeping<class_RigidBody2D_property_sleeping>`.
  252. .. rst-class:: classref-item-separator
  253. ----
  254. .. _class_RigidBody2D_property_center_of_mass:
  255. .. rst-class:: classref-property
  256. :ref:`Vector2<class_Vector2>` **center_of_mass** = ``Vector2(0, 0)`` :ref:`🔗<class_RigidBody2D_property_center_of_mass>`
  257. .. rst-class:: classref-property-setget
  258. - |void| **set_center_of_mass**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
  259. - :ref:`Vector2<class_Vector2>` **get_center_of_mass**\ (\ )
  260. The body's custom center of mass, relative to the body's origin position, when :ref:`center_of_mass_mode<class_RigidBody2D_property_center_of_mass_mode>` is set to :ref:`CENTER_OF_MASS_MODE_CUSTOM<class_RigidBody2D_constant_CENTER_OF_MASS_MODE_CUSTOM>`. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration.
  261. When :ref:`center_of_mass_mode<class_RigidBody2D_property_center_of_mass_mode>` is set to :ref:`CENTER_OF_MASS_MODE_AUTO<class_RigidBody2D_constant_CENTER_OF_MASS_MODE_AUTO>` (default value), the center of mass is automatically computed.
  262. .. rst-class:: classref-item-separator
  263. ----
  264. .. _class_RigidBody2D_property_center_of_mass_mode:
  265. .. rst-class:: classref-property
  266. :ref:`CenterOfMassMode<enum_RigidBody2D_CenterOfMassMode>` **center_of_mass_mode** = ``0`` :ref:`🔗<class_RigidBody2D_property_center_of_mass_mode>`
  267. .. rst-class:: classref-property-setget
  268. - |void| **set_center_of_mass_mode**\ (\ value\: :ref:`CenterOfMassMode<enum_RigidBody2D_CenterOfMassMode>`\ )
  269. - :ref:`CenterOfMassMode<enum_RigidBody2D_CenterOfMassMode>` **get_center_of_mass_mode**\ (\ )
  270. Defines the way the body's center of mass is set. See :ref:`CenterOfMassMode<enum_RigidBody2D_CenterOfMassMode>` for possible values.
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_RigidBody2D_property_constant_force:
  274. .. rst-class:: classref-property
  275. :ref:`Vector2<class_Vector2>` **constant_force** = ``Vector2(0, 0)`` :ref:`🔗<class_RigidBody2D_property_constant_force>`
  276. .. rst-class:: classref-property-setget
  277. - |void| **set_constant_force**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
  278. - :ref:`Vector2<class_Vector2>` **get_constant_force**\ (\ )
  279. The body's total constant positional forces applied during each physics update.
  280. See :ref:`add_constant_force<class_RigidBody2D_method_add_constant_force>` and :ref:`add_constant_central_force<class_RigidBody2D_method_add_constant_central_force>`.
  281. .. rst-class:: classref-item-separator
  282. ----
  283. .. _class_RigidBody2D_property_constant_torque:
  284. .. rst-class:: classref-property
  285. :ref:`float<class_float>` **constant_torque** = ``0.0`` :ref:`🔗<class_RigidBody2D_property_constant_torque>`
  286. .. rst-class:: classref-property-setget
  287. - |void| **set_constant_torque**\ (\ value\: :ref:`float<class_float>`\ )
  288. - :ref:`float<class_float>` **get_constant_torque**\ (\ )
  289. The body's total constant rotational forces applied during each physics update.
  290. See :ref:`add_constant_torque<class_RigidBody2D_method_add_constant_torque>`.
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _class_RigidBody2D_property_contact_monitor:
  294. .. rst-class:: classref-property
  295. :ref:`bool<class_bool>` **contact_monitor** = ``false`` :ref:`🔗<class_RigidBody2D_property_contact_monitor>`
  296. .. rst-class:: classref-property-setget
  297. - |void| **set_contact_monitor**\ (\ value\: :ref:`bool<class_bool>`\ )
  298. - :ref:`bool<class_bool>` **is_contact_monitor_enabled**\ (\ )
  299. If ``true``, the RigidBody2D will emit signals when it collides with another body.
  300. \ **Note:** By default the maximum contacts reported is set to 0, meaning nothing will be recorded, see :ref:`max_contacts_reported<class_RigidBody2D_property_max_contacts_reported>`.
  301. .. rst-class:: classref-item-separator
  302. ----
  303. .. _class_RigidBody2D_property_continuous_cd:
  304. .. rst-class:: classref-property
  305. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **continuous_cd** = ``0`` :ref:`🔗<class_RigidBody2D_property_continuous_cd>`
  306. .. rst-class:: classref-property-setget
  307. - |void| **set_continuous_collision_detection_mode**\ (\ value\: :ref:`CCDMode<enum_RigidBody2D_CCDMode>`\ )
  308. - :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **get_continuous_collision_detection_mode**\ (\ )
  309. Continuous collision detection mode.
  310. Continuous collision detection tries to predict where a moving body will collide instead of moving it and correcting its movement after collision. Continuous collision detection is slower, but more precise and misses fewer collisions with small, fast-moving objects. Raycasting and shapecasting methods are available. See :ref:`CCDMode<enum_RigidBody2D_CCDMode>` for details.
  311. .. rst-class:: classref-item-separator
  312. ----
  313. .. _class_RigidBody2D_property_custom_integrator:
  314. .. rst-class:: classref-property
  315. :ref:`bool<class_bool>` **custom_integrator** = ``false`` :ref:`🔗<class_RigidBody2D_property_custom_integrator>`
  316. .. rst-class:: classref-property-setget
  317. - |void| **set_use_custom_integrator**\ (\ value\: :ref:`bool<class_bool>`\ )
  318. - :ref:`bool<class_bool>` **is_using_custom_integrator**\ (\ )
  319. If ``true``, the standard force integration (like gravity or damping) will be disabled for this body. Other than collision response, the body will only move as determined by the :ref:`_integrate_forces<class_RigidBody2D_private_method__integrate_forces>` method, if that virtual method is overridden.
  320. Setting this property will call the method :ref:`PhysicsServer2D.body_set_omit_force_integration<class_PhysicsServer2D_method_body_set_omit_force_integration>` internally.
  321. .. rst-class:: classref-item-separator
  322. ----
  323. .. _class_RigidBody2D_property_freeze:
  324. .. rst-class:: classref-property
  325. :ref:`bool<class_bool>` **freeze** = ``false`` :ref:`🔗<class_RigidBody2D_property_freeze>`
  326. .. rst-class:: classref-property-setget
  327. - |void| **set_freeze_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  328. - :ref:`bool<class_bool>` **is_freeze_enabled**\ (\ )
  329. If ``true``, the body is frozen. Gravity and forces are not applied anymore.
  330. See :ref:`freeze_mode<class_RigidBody2D_property_freeze_mode>` to set the body's behavior when frozen.
  331. For a body that is always frozen, use :ref:`StaticBody2D<class_StaticBody2D>` or :ref:`AnimatableBody2D<class_AnimatableBody2D>` instead.
  332. .. rst-class:: classref-item-separator
  333. ----
  334. .. _class_RigidBody2D_property_freeze_mode:
  335. .. rst-class:: classref-property
  336. :ref:`FreezeMode<enum_RigidBody2D_FreezeMode>` **freeze_mode** = ``0`` :ref:`🔗<class_RigidBody2D_property_freeze_mode>`
  337. .. rst-class:: classref-property-setget
  338. - |void| **set_freeze_mode**\ (\ value\: :ref:`FreezeMode<enum_RigidBody2D_FreezeMode>`\ )
  339. - :ref:`FreezeMode<enum_RigidBody2D_FreezeMode>` **get_freeze_mode**\ (\ )
  340. The body's freeze mode. Can be used to set the body's behavior when :ref:`freeze<class_RigidBody2D_property_freeze>` is enabled. See :ref:`FreezeMode<enum_RigidBody2D_FreezeMode>` for possible values.
  341. For a body that is always frozen, use :ref:`StaticBody2D<class_StaticBody2D>` or :ref:`AnimatableBody2D<class_AnimatableBody2D>` instead.
  342. .. rst-class:: classref-item-separator
  343. ----
  344. .. _class_RigidBody2D_property_gravity_scale:
  345. .. rst-class:: classref-property
  346. :ref:`float<class_float>` **gravity_scale** = ``1.0`` :ref:`🔗<class_RigidBody2D_property_gravity_scale>`
  347. .. rst-class:: classref-property-setget
  348. - |void| **set_gravity_scale**\ (\ value\: :ref:`float<class_float>`\ )
  349. - :ref:`float<class_float>` **get_gravity_scale**\ (\ )
  350. Multiplies the gravity applied to the body. The body's gravity is calculated from the :ref:`ProjectSettings.physics/2d/default_gravity<class_ProjectSettings_property_physics/2d/default_gravity>` project setting and/or any additional gravity vector applied by :ref:`Area2D<class_Area2D>`\ s.
  351. .. rst-class:: classref-item-separator
  352. ----
  353. .. _class_RigidBody2D_property_inertia:
  354. .. rst-class:: classref-property
  355. :ref:`float<class_float>` **inertia** = ``0.0`` :ref:`🔗<class_RigidBody2D_property_inertia>`
  356. .. rst-class:: classref-property-setget
  357. - |void| **set_inertia**\ (\ value\: :ref:`float<class_float>`\ )
  358. - :ref:`float<class_float>` **get_inertia**\ (\ )
  359. The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value.
  360. If set to ``0``, inertia is automatically computed (default value).
  361. \ **Note:** This value does not change when inertia is automatically computed. Use :ref:`PhysicsServer2D<class_PhysicsServer2D>` to get the computed inertia.
  362. .. tabs::
  363. .. code-tab:: gdscript
  364. @onready var ball = $Ball
  365. func get_ball_inertia():
  366. return 1.0 / PhysicsServer2D.body_get_direct_state(ball.get_rid()).inverse_inertia
  367. .. code-tab:: csharp
  368. private RigidBody2D _ball;
  369. public override void _Ready()
  370. {
  371. _ball = GetNode<RigidBody2D>("Ball");
  372. }
  373. private float GetBallInertia()
  374. {
  375. return 1.0f / PhysicsServer2D.BodyGetDirectState(_ball.GetRid()).InverseInertia;
  376. }
  377. .. rst-class:: classref-item-separator
  378. ----
  379. .. _class_RigidBody2D_property_linear_damp:
  380. .. rst-class:: classref-property
  381. :ref:`float<class_float>` **linear_damp** = ``0.0`` :ref:`🔗<class_RigidBody2D_property_linear_damp>`
  382. .. rst-class:: classref-property-setget
  383. - |void| **set_linear_damp**\ (\ value\: :ref:`float<class_float>`\ )
  384. - :ref:`float<class_float>` **get_linear_damp**\ (\ )
  385. Damps the body's movement. By default, the body will use the :ref:`ProjectSettings.physics/2d/default_linear_damp<class_ProjectSettings_property_physics/2d/default_linear_damp>` setting or any value override set by an :ref:`Area2D<class_Area2D>` the body is in. Depending on :ref:`linear_damp_mode<class_RigidBody2D_property_linear_damp_mode>`, you can set :ref:`linear_damp<class_RigidBody2D_property_linear_damp>` to be added to or to replace the body's damping value.
  386. See :ref:`ProjectSettings.physics/2d/default_linear_damp<class_ProjectSettings_property_physics/2d/default_linear_damp>` for more details about damping.
  387. .. rst-class:: classref-item-separator
  388. ----
  389. .. _class_RigidBody2D_property_linear_damp_mode:
  390. .. rst-class:: classref-property
  391. :ref:`DampMode<enum_RigidBody2D_DampMode>` **linear_damp_mode** = ``0`` :ref:`🔗<class_RigidBody2D_property_linear_damp_mode>`
  392. .. rst-class:: classref-property-setget
  393. - |void| **set_linear_damp_mode**\ (\ value\: :ref:`DampMode<enum_RigidBody2D_DampMode>`\ )
  394. - :ref:`DampMode<enum_RigidBody2D_DampMode>` **get_linear_damp_mode**\ (\ )
  395. Defines how :ref:`linear_damp<class_RigidBody2D_property_linear_damp>` is applied. See :ref:`DampMode<enum_RigidBody2D_DampMode>` for possible values.
  396. .. rst-class:: classref-item-separator
  397. ----
  398. .. _class_RigidBody2D_property_linear_velocity:
  399. .. rst-class:: classref-property
  400. :ref:`Vector2<class_Vector2>` **linear_velocity** = ``Vector2(0, 0)`` :ref:`🔗<class_RigidBody2D_property_linear_velocity>`
  401. .. rst-class:: classref-property-setget
  402. - |void| **set_linear_velocity**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
  403. - :ref:`Vector2<class_Vector2>` **get_linear_velocity**\ (\ )
  404. The body's linear velocity in pixels per second. Can be used sporadically, but **don't set this every frame**, because physics may run in another thread and runs at a different granularity. Use :ref:`_integrate_forces<class_RigidBody2D_private_method__integrate_forces>` as your process loop for precise control of the body state.
  405. .. rst-class:: classref-item-separator
  406. ----
  407. .. _class_RigidBody2D_property_lock_rotation:
  408. .. rst-class:: classref-property
  409. :ref:`bool<class_bool>` **lock_rotation** = ``false`` :ref:`🔗<class_RigidBody2D_property_lock_rotation>`
  410. .. rst-class:: classref-property-setget
  411. - |void| **set_lock_rotation_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  412. - :ref:`bool<class_bool>` **is_lock_rotation_enabled**\ (\ )
  413. If ``true``, the body cannot rotate. Gravity and forces only apply linear movement.
  414. .. rst-class:: classref-item-separator
  415. ----
  416. .. _class_RigidBody2D_property_mass:
  417. .. rst-class:: classref-property
  418. :ref:`float<class_float>` **mass** = ``1.0`` :ref:`🔗<class_RigidBody2D_property_mass>`
  419. .. rst-class:: classref-property-setget
  420. - |void| **set_mass**\ (\ value\: :ref:`float<class_float>`\ )
  421. - :ref:`float<class_float>` **get_mass**\ (\ )
  422. The body's mass.
  423. .. rst-class:: classref-item-separator
  424. ----
  425. .. _class_RigidBody2D_property_max_contacts_reported:
  426. .. rst-class:: classref-property
  427. :ref:`int<class_int>` **max_contacts_reported** = ``0`` :ref:`🔗<class_RigidBody2D_property_max_contacts_reported>`
  428. .. rst-class:: classref-property-setget
  429. - |void| **set_max_contacts_reported**\ (\ value\: :ref:`int<class_int>`\ )
  430. - :ref:`int<class_int>` **get_max_contacts_reported**\ (\ )
  431. The maximum number of contacts that will be recorded. Requires a value greater than 0 and :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to be set to ``true`` to start to register contacts. Use :ref:`get_contact_count<class_RigidBody2D_method_get_contact_count>` to retrieve the count or :ref:`get_colliding_bodies<class_RigidBody2D_method_get_colliding_bodies>` to retrieve bodies that have been collided with.
  432. \ **Note:** The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end), and collisions between parallel faces will result in four contacts (one at each corner).
  433. .. rst-class:: classref-item-separator
  434. ----
  435. .. _class_RigidBody2D_property_physics_material_override:
  436. .. rst-class:: classref-property
  437. :ref:`PhysicsMaterial<class_PhysicsMaterial>` **physics_material_override** :ref:`🔗<class_RigidBody2D_property_physics_material_override>`
  438. .. rst-class:: classref-property-setget
  439. - |void| **set_physics_material_override**\ (\ value\: :ref:`PhysicsMaterial<class_PhysicsMaterial>`\ )
  440. - :ref:`PhysicsMaterial<class_PhysicsMaterial>` **get_physics_material_override**\ (\ )
  441. The physics material override for the body.
  442. If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one.
  443. .. rst-class:: classref-item-separator
  444. ----
  445. .. _class_RigidBody2D_property_sleeping:
  446. .. rst-class:: classref-property
  447. :ref:`bool<class_bool>` **sleeping** = ``false`` :ref:`🔗<class_RigidBody2D_property_sleeping>`
  448. .. rst-class:: classref-property-setget
  449. - |void| **set_sleeping**\ (\ value\: :ref:`bool<class_bool>`\ )
  450. - :ref:`bool<class_bool>` **is_sleeping**\ (\ )
  451. If ``true``, the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the :ref:`apply_impulse<class_RigidBody2D_method_apply_impulse>` or :ref:`apply_force<class_RigidBody2D_method_apply_force>` methods.
  452. .. rst-class:: classref-section-separator
  453. ----
  454. .. rst-class:: classref-descriptions-group
  455. Method Descriptions
  456. -------------------
  457. .. _class_RigidBody2D_private_method__integrate_forces:
  458. .. rst-class:: classref-method
  459. |void| **_integrate_forces**\ (\ state\: :ref:`PhysicsDirectBodyState2D<class_PhysicsDirectBodyState2D>`\ ) |virtual| :ref:`🔗<class_RigidBody2D_private_method__integrate_forces>`
  460. Called during physics processing, allowing you to read and safely modify the simulation state for the object. By default, it is called before the standard force integration, but the :ref:`custom_integrator<class_RigidBody2D_property_custom_integrator>` property allows you to disable the standard force integration and do fully custom force integration for a body.
  461. .. rst-class:: classref-item-separator
  462. ----
  463. .. _class_RigidBody2D_method_add_constant_central_force:
  464. .. rst-class:: classref-method
  465. |void| **add_constant_central_force**\ (\ force\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_RigidBody2D_method_add_constant_central_force>`
  466. Adds a constant directional force without affecting rotation that keeps being applied over time until cleared with ``constant_force = Vector2(0, 0)``.
  467. This is equivalent to using :ref:`add_constant_force<class_RigidBody2D_method_add_constant_force>` at the body's center of mass.
  468. .. rst-class:: classref-item-separator
  469. ----
  470. .. _class_RigidBody2D_method_add_constant_force:
  471. .. rst-class:: classref-method
  472. |void| **add_constant_force**\ (\ force\: :ref:`Vector2<class_Vector2>`, position\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) :ref:`🔗<class_RigidBody2D_method_add_constant_force>`
  473. Adds a constant positioned force to the body that keeps being applied over time until cleared with ``constant_force = Vector2(0, 0)``.
  474. \ ``position`` is the offset from the body origin in global coordinates.
  475. .. rst-class:: classref-item-separator
  476. ----
  477. .. _class_RigidBody2D_method_add_constant_torque:
  478. .. rst-class:: classref-method
  479. |void| **add_constant_torque**\ (\ torque\: :ref:`float<class_float>`\ ) :ref:`🔗<class_RigidBody2D_method_add_constant_torque>`
  480. Adds a constant rotational force without affecting position that keeps being applied over time until cleared with ``constant_torque = 0``.
  481. .. rst-class:: classref-item-separator
  482. ----
  483. .. _class_RigidBody2D_method_apply_central_force:
  484. .. rst-class:: classref-method
  485. |void| **apply_central_force**\ (\ force\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_RigidBody2D_method_apply_central_force>`
  486. Applies a directional force without affecting rotation. A force is time dependent and meant to be applied every physics update.
  487. This is equivalent to using :ref:`apply_force<class_RigidBody2D_method_apply_force>` at the body's center of mass.
  488. .. rst-class:: classref-item-separator
  489. ----
  490. .. _class_RigidBody2D_method_apply_central_impulse:
  491. .. rst-class:: classref-method
  492. |void| **apply_central_impulse**\ (\ impulse\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) :ref:`🔗<class_RigidBody2D_method_apply_central_impulse>`
  493. Applies a directional impulse without affecting rotation.
  494. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
  495. This is equivalent to using :ref:`apply_impulse<class_RigidBody2D_method_apply_impulse>` at the body's center of mass.
  496. .. rst-class:: classref-item-separator
  497. ----
  498. .. _class_RigidBody2D_method_apply_force:
  499. .. rst-class:: classref-method
  500. |void| **apply_force**\ (\ force\: :ref:`Vector2<class_Vector2>`, position\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) :ref:`🔗<class_RigidBody2D_method_apply_force>`
  501. Applies a positioned force to the body. A force is time dependent and meant to be applied every physics update.
  502. \ ``position`` is the offset from the body origin in global coordinates.
  503. .. rst-class:: classref-item-separator
  504. ----
  505. .. _class_RigidBody2D_method_apply_impulse:
  506. .. rst-class:: classref-method
  507. |void| **apply_impulse**\ (\ impulse\: :ref:`Vector2<class_Vector2>`, position\: :ref:`Vector2<class_Vector2>` = Vector2(0, 0)\ ) :ref:`🔗<class_RigidBody2D_method_apply_impulse>`
  508. Applies a positioned impulse to the body.
  509. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
  510. \ ``position`` is the offset from the body origin in global coordinates.
  511. .. rst-class:: classref-item-separator
  512. ----
  513. .. _class_RigidBody2D_method_apply_torque:
  514. .. rst-class:: classref-method
  515. |void| **apply_torque**\ (\ torque\: :ref:`float<class_float>`\ ) :ref:`🔗<class_RigidBody2D_method_apply_torque>`
  516. Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.
  517. \ **Note:** :ref:`inertia<class_RigidBody2D_property_inertia>` is required for this to work. To have :ref:`inertia<class_RigidBody2D_property_inertia>`, an active :ref:`CollisionShape2D<class_CollisionShape2D>` must be a child of the node, or you can manually set :ref:`inertia<class_RigidBody2D_property_inertia>`.
  518. .. rst-class:: classref-item-separator
  519. ----
  520. .. _class_RigidBody2D_method_apply_torque_impulse:
  521. .. rst-class:: classref-method
  522. |void| **apply_torque_impulse**\ (\ torque\: :ref:`float<class_float>`\ ) :ref:`🔗<class_RigidBody2D_method_apply_torque_impulse>`
  523. Applies a rotational impulse to the body without affecting the position.
  524. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
  525. \ **Note:** :ref:`inertia<class_RigidBody2D_property_inertia>` is required for this to work. To have :ref:`inertia<class_RigidBody2D_property_inertia>`, an active :ref:`CollisionShape2D<class_CollisionShape2D>` must be a child of the node, or you can manually set :ref:`inertia<class_RigidBody2D_property_inertia>`.
  526. .. rst-class:: classref-item-separator
  527. ----
  528. .. _class_RigidBody2D_method_get_colliding_bodies:
  529. .. rst-class:: classref-method
  530. :ref:`Array<class_Array>`\[:ref:`Node2D<class_Node2D>`\] **get_colliding_bodies**\ (\ ) |const| :ref:`🔗<class_RigidBody2D_method_get_colliding_bodies>`
  531. Returns a list of the bodies colliding with this one. Requires :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`max_contacts_reported<class_RigidBody2D_property_max_contacts_reported>` to be set high enough to detect all the collisions.
  532. \ **Note:** The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.
  533. .. rst-class:: classref-item-separator
  534. ----
  535. .. _class_RigidBody2D_method_get_contact_count:
  536. .. rst-class:: classref-method
  537. :ref:`int<class_int>` **get_contact_count**\ (\ ) |const| :ref:`🔗<class_RigidBody2D_method_get_contact_count>`
  538. Returns the number of contacts this body has with other bodies. By default, this returns 0 unless bodies are configured to monitor contacts (see :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>`).
  539. \ **Note:** To retrieve the colliding bodies, use :ref:`get_colliding_bodies<class_RigidBody2D_method_get_colliding_bodies>`.
  540. .. rst-class:: classref-item-separator
  541. ----
  542. .. _class_RigidBody2D_method_set_axis_velocity:
  543. .. rst-class:: classref-method
  544. |void| **set_axis_velocity**\ (\ axis_velocity\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_RigidBody2D_method_set_axis_velocity>`
  545. Sets the body's velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
  546. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  547. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  548. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  549. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  550. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  551. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  552. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  553. .. |void| replace:: :abbr:`void (No return value.)`