class_rigiddynamicbody2d.rst 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the RigidDynamicBody2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_RigidDynamicBody2D:
  6. RigidDynamicBody2D
  7. ==================
  8. **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>`
  9. **Inherited By:** :ref:`PhysicalBone2D<class_PhysicalBone2D>`
  10. Physics Body which is moved by 2D physics simulation. Useful for objects that have gravity and can be pushed by other objects.
  11. Description
  12. -----------
  13. This node implements simulated 2D physics. You do not control a RigidDynamicBody2D directly. Instead, you apply forces to it (gravity, impulses, etc.) and the physics simulation calculates the resulting movement based on its mass, friction, and other physical properties.
  14. You can switch the body's behavior using :ref:`lock_rotation<class_RigidDynamicBody2D_property_lock_rotation>`, :ref:`freeze<class_RigidDynamicBody2D_property_freeze>`, and :ref:`freeze_mode<class_RigidDynamicBody2D_property_freeze_mode>`.
  15. **Note:** You should not change a RigidDynamicBody2D's ``position`` or ``linear_velocity`` every frame or even very often. If you need to directly affect the body's state, use :ref:`_integrate_forces<class_RigidDynamicBody2D_method__integrate_forces>`, which allows you to directly access the physics state.
  16. Please also keep in mind that physics bodies manage their own transform which overwrites the ones you set. So any direct or indirect transformation (including scaling of the node or its parent) will be visible in the editor only, and immediately reset at runtime.
  17. If you need to override the default physics behavior or add a transformation at runtime, you can write a custom force integration. See :ref:`custom_integrator<class_RigidDynamicBody2D_property_custom_integrator>`.
  18. Tutorials
  19. ---------
  20. - `2D Physics Platformer Demo <https://godotengine.org/asset-library/asset/119>`__
  21. - `Instancing Demo <https://godotengine.org/asset-library/asset/148>`__
  22. Properties
  23. ----------
  24. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  25. | :ref:`float<class_float>` | :ref:`angular_damp<class_RigidDynamicBody2D_property_angular_damp>` | ``0.0`` |
  26. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  27. | :ref:`DampMode<enum_RigidDynamicBody2D_DampMode>` | :ref:`angular_damp_mode<class_RigidDynamicBody2D_property_angular_damp_mode>` | ``0`` |
  28. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  29. | :ref:`float<class_float>` | :ref:`angular_velocity<class_RigidDynamicBody2D_property_angular_velocity>` | ``0.0`` |
  30. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  31. | :ref:`Vector2<class_Vector2>` | :ref:`applied_force<class_RigidDynamicBody2D_property_applied_force>` | ``Vector2(0, 0)`` |
  32. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  33. | :ref:`float<class_float>` | :ref:`applied_torque<class_RigidDynamicBody2D_property_applied_torque>` | ``0.0`` |
  34. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  35. | :ref:`bool<class_bool>` | :ref:`can_sleep<class_RigidDynamicBody2D_property_can_sleep>` | ``true`` |
  36. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  37. | :ref:`Vector2<class_Vector2>` | :ref:`center_of_mass<class_RigidDynamicBody2D_property_center_of_mass>` | ``Vector2(0, 0)`` |
  38. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  39. | :ref:`CenterOfMassMode<enum_RigidDynamicBody2D_CenterOfMassMode>` | :ref:`center_of_mass_mode<class_RigidDynamicBody2D_property_center_of_mass_mode>` | ``0`` |
  40. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  41. | :ref:`bool<class_bool>` | :ref:`contact_monitor<class_RigidDynamicBody2D_property_contact_monitor>` | ``false`` |
  42. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  43. | :ref:`int<class_int>` | :ref:`contacts_reported<class_RigidDynamicBody2D_property_contacts_reported>` | ``0`` |
  44. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  45. | :ref:`CCDMode<enum_RigidDynamicBody2D_CCDMode>` | :ref:`continuous_cd<class_RigidDynamicBody2D_property_continuous_cd>` | ``0`` |
  46. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  47. | :ref:`bool<class_bool>` | :ref:`custom_integrator<class_RigidDynamicBody2D_property_custom_integrator>` | ``false`` |
  48. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  49. | :ref:`bool<class_bool>` | :ref:`freeze<class_RigidDynamicBody2D_property_freeze>` | ``false`` |
  50. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  51. | :ref:`FreezeMode<enum_RigidDynamicBody2D_FreezeMode>` | :ref:`freeze_mode<class_RigidDynamicBody2D_property_freeze_mode>` | ``0`` |
  52. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  53. | :ref:`float<class_float>` | :ref:`gravity_scale<class_RigidDynamicBody2D_property_gravity_scale>` | ``1.0`` |
  54. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  55. | :ref:`float<class_float>` | :ref:`inertia<class_RigidDynamicBody2D_property_inertia>` | ``0.0`` |
  56. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  57. | :ref:`float<class_float>` | :ref:`linear_damp<class_RigidDynamicBody2D_property_linear_damp>` | ``0.0`` |
  58. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  59. | :ref:`DampMode<enum_RigidDynamicBody2D_DampMode>` | :ref:`linear_damp_mode<class_RigidDynamicBody2D_property_linear_damp_mode>` | ``0`` |
  60. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  61. | :ref:`Vector2<class_Vector2>` | :ref:`linear_velocity<class_RigidDynamicBody2D_property_linear_velocity>` | ``Vector2(0, 0)`` |
  62. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  63. | :ref:`bool<class_bool>` | :ref:`lock_rotation<class_RigidDynamicBody2D_property_lock_rotation>` | ``false`` |
  64. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  65. | :ref:`float<class_float>` | :ref:`mass<class_RigidDynamicBody2D_property_mass>` | ``1.0`` |
  66. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  67. | :ref:`PhysicsMaterial<class_PhysicsMaterial>` | :ref:`physics_material_override<class_RigidDynamicBody2D_property_physics_material_override>` | |
  68. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  69. | :ref:`bool<class_bool>` | :ref:`sleeping<class_RigidDynamicBody2D_property_sleeping>` | ``false`` |
  70. +-------------------------------------------------------------------+-----------------------------------------------------------------------------------------------+-------------------+
  71. Methods
  72. -------
  73. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`_integrate_forces<class_RigidDynamicBody2D_method__integrate_forces>` **(** :ref:`PhysicsDirectBodyState2D<class_PhysicsDirectBodyState2D>` state **)** |virtual| |
  75. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`add_central_force<class_RigidDynamicBody2D_method_add_central_force>` **(** :ref:`Vector2<class_Vector2>` force **)** |
  77. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`add_force<class_RigidDynamicBody2D_method_add_force>` **(** :ref:`Vector2<class_Vector2>` force, :ref:`Vector2<class_Vector2>` position=Vector2(0, 0) **)** |
  79. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`add_torque<class_RigidDynamicBody2D_method_add_torque>` **(** :ref:`float<class_float>` torque **)** |
  81. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`apply_central_impulse<class_RigidDynamicBody2D_method_apply_central_impulse>` **(** :ref:`Vector2<class_Vector2>` impulse=Vector2(0, 0) **)** |
  83. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`apply_impulse<class_RigidDynamicBody2D_method_apply_impulse>` **(** :ref:`Vector2<class_Vector2>` impulse, :ref:`Vector2<class_Vector2>` position=Vector2(0, 0) **)** |
  85. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | void | :ref:`apply_torque_impulse<class_RigidDynamicBody2D_method_apply_torque_impulse>` **(** :ref:`float<class_float>` torque **)** |
  87. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Node2D[]<class_Node2D>` | :ref:`get_colliding_bodies<class_RigidDynamicBody2D_method_get_colliding_bodies>` **(** **)** |const| |
  89. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | void | :ref:`set_axis_velocity<class_RigidDynamicBody2D_method_set_axis_velocity>` **(** :ref:`Vector2<class_Vector2>` axis_velocity **)** |
  91. +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. Signals
  93. -------
  94. .. _class_RigidDynamicBody2D_signal_body_entered:
  95. - **body_entered** **(** :ref:`Node<class_Node>` body **)**
  96. Emitted when a collision with another :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>` occurs. Requires :ref:`contact_monitor<class_RigidDynamicBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidDynamicBody2D_property_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.
  97. ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  98. ----
  99. .. _class_RigidDynamicBody2D_signal_body_exited:
  100. - **body_exited** **(** :ref:`Node<class_Node>` body **)**
  101. Emitted when the collision with another :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>` ends. Requires :ref:`contact_monitor<class_RigidDynamicBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidDynamicBody2D_property_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.
  102. ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  103. ----
  104. .. _class_RigidDynamicBody2D_signal_body_shape_entered:
  105. - **body_shape_entered** **(** :ref:`RID<class_RID>` body_rid, :ref:`Node<class_Node>` body, :ref:`int<class_int>` body_shape_index, :ref:`int<class_int>` local_shape_index **)**
  106. Emitted when one of this RigidDynamicBody2D'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_RigidDynamicBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidDynamicBody2D_property_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.
  107. ``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>`.
  108. ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  109. ``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_index)``.
  110. ``local_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of this RigidDynamicBody2D used by the :ref:`PhysicsServer2D<class_PhysicsServer2D>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``self.shape_owner_get_owner(local_shape_index)``.
  111. ----
  112. .. _class_RigidDynamicBody2D_signal_body_shape_exited:
  113. - **body_shape_exited** **(** :ref:`RID<class_RID>` body_rid, :ref:`Node<class_Node>` body, :ref:`int<class_int>` body_shape_index, :ref:`int<class_int>` local_shape_index **)**
  114. Emitted when the collision between one of this RigidDynamicBody2D'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_RigidDynamicBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidDynamicBody2D_property_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.
  115. ``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>`.
  116. ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  117. ``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_index)``.
  118. ``local_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of this RigidDynamicBody2D used by the :ref:`PhysicsServer2D<class_PhysicsServer2D>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``self.shape_owner_get_owner(local_shape_index)``.
  119. ----
  120. .. _class_RigidDynamicBody2D_signal_sleeping_state_changed:
  121. - **sleeping_state_changed** **(** **)**
  122. Emitted when the physics engine changes the body's sleeping state.
  123. **Note:** Changing the value :ref:`sleeping<class_RigidDynamicBody2D_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.
  124. Enumerations
  125. ------------
  126. .. _enum_RigidDynamicBody2D_FreezeMode:
  127. .. _class_RigidDynamicBody2D_constant_FREEZE_MODE_STATIC:
  128. .. _class_RigidDynamicBody2D_constant_FREEZE_MODE_KINEMATIC:
  129. enum **FreezeMode**:
  130. - **FREEZE_MODE_STATIC** = **0** --- 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.
  131. - **FREEZE_MODE_KINEMATIC** = **1** --- Kinematic body freeze mode. Similar to :ref:`FREEZE_MODE_STATIC<class_RigidDynamicBody2D_constant_FREEZE_MODE_STATIC>`, but collides with other bodies along its path when moved. Useful for a frozen body that needs to be animated.
  132. ----
  133. .. _enum_RigidDynamicBody2D_CenterOfMassMode:
  134. .. _class_RigidDynamicBody2D_constant_CENTER_OF_MASS_MODE_AUTO:
  135. .. _class_RigidDynamicBody2D_constant_CENTER_OF_MASS_MODE_CUSTOM:
  136. enum **CenterOfMassMode**:
  137. - **CENTER_OF_MASS_MODE_AUTO** = **0** --- In this mode, the body's center of mass is calculated automatically based on its shapes.
  138. - **CENTER_OF_MASS_MODE_CUSTOM** = **1** --- In this mode, the body's center of mass is set through :ref:`center_of_mass<class_RigidDynamicBody2D_property_center_of_mass>`. Defaults to the body's origin position.
  139. ----
  140. .. _enum_RigidDynamicBody2D_DampMode:
  141. .. _class_RigidDynamicBody2D_constant_DAMP_MODE_COMBINE:
  142. .. _class_RigidDynamicBody2D_constant_DAMP_MODE_REPLACE:
  143. enum **DampMode**:
  144. - **DAMP_MODE_COMBINE** = **0** --- In this mode, the body's damping value is added to any value set in areas or the default value.
  145. - **DAMP_MODE_REPLACE** = **1** --- In this mode, the body's damping value replaces any value set in areas or the default value.
  146. ----
  147. .. _enum_RigidDynamicBody2D_CCDMode:
  148. .. _class_RigidDynamicBody2D_constant_CCD_MODE_DISABLED:
  149. .. _class_RigidDynamicBody2D_constant_CCD_MODE_CAST_RAY:
  150. .. _class_RigidDynamicBody2D_constant_CCD_MODE_CAST_SHAPE:
  151. enum **CCDMode**:
  152. - **CCD_MODE_DISABLED** = **0** --- Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
  153. - **CCD_MODE_CAST_RAY** = **1** --- Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise.
  154. - **CCD_MODE_CAST_SHAPE** = **2** --- Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise.
  155. Property Descriptions
  156. ---------------------
  157. .. _class_RigidDynamicBody2D_property_angular_damp:
  158. - :ref:`float<class_float>` **angular_damp**
  159. +-----------+-------------------------+
  160. | *Default* | ``0.0`` |
  161. +-----------+-------------------------+
  162. | *Setter* | set_angular_damp(value) |
  163. +-----------+-------------------------+
  164. | *Getter* | get_angular_damp() |
  165. +-----------+-------------------------+
  166. Damps the body's rotation. By default, the body will use the **Default Angular Damp** in **Project > Project Settings > Physics > 2d** or any value override set by an :ref:`Area2D<class_Area2D>` the body is in. Depending on :ref:`angular_damp_mode<class_RigidDynamicBody2D_property_angular_damp_mode>`, you can set :ref:`angular_damp<class_RigidDynamicBody2D_property_angular_damp>` to be added to or to replace the body's damping value.
  167. See :ref:`ProjectSettings.physics/2d/default_angular_damp<class_ProjectSettings_property_physics/2d/default_angular_damp>` for more details about damping.
  168. ----
  169. .. _class_RigidDynamicBody2D_property_angular_damp_mode:
  170. - :ref:`DampMode<enum_RigidDynamicBody2D_DampMode>` **angular_damp_mode**
  171. +-----------+------------------------------+
  172. | *Default* | ``0`` |
  173. +-----------+------------------------------+
  174. | *Setter* | set_angular_damp_mode(value) |
  175. +-----------+------------------------------+
  176. | *Getter* | get_angular_damp_mode() |
  177. +-----------+------------------------------+
  178. Defines how :ref:`angular_damp<class_RigidDynamicBody2D_property_angular_damp>` is applied. See :ref:`DampMode<enum_RigidDynamicBody2D_DampMode>` for possible values.
  179. ----
  180. .. _class_RigidDynamicBody2D_property_angular_velocity:
  181. - :ref:`float<class_float>` **angular_velocity**
  182. +-----------+-----------------------------+
  183. | *Default* | ``0.0`` |
  184. +-----------+-----------------------------+
  185. | *Setter* | set_angular_velocity(value) |
  186. +-----------+-----------------------------+
  187. | *Getter* | get_angular_velocity() |
  188. +-----------+-----------------------------+
  189. The body's rotational velocity.
  190. ----
  191. .. _class_RigidDynamicBody2D_property_applied_force:
  192. - :ref:`Vector2<class_Vector2>` **applied_force**
  193. +-----------+--------------------------+
  194. | *Default* | ``Vector2(0, 0)`` |
  195. +-----------+--------------------------+
  196. | *Setter* | set_applied_force(value) |
  197. +-----------+--------------------------+
  198. | *Getter* | get_applied_force() |
  199. +-----------+--------------------------+
  200. The body's total applied force.
  201. ----
  202. .. _class_RigidDynamicBody2D_property_applied_torque:
  203. - :ref:`float<class_float>` **applied_torque**
  204. +-----------+---------------------------+
  205. | *Default* | ``0.0`` |
  206. +-----------+---------------------------+
  207. | *Setter* | set_applied_torque(value) |
  208. +-----------+---------------------------+
  209. | *Getter* | get_applied_torque() |
  210. +-----------+---------------------------+
  211. The body's total applied torque.
  212. ----
  213. .. _class_RigidDynamicBody2D_property_can_sleep:
  214. - :ref:`bool<class_bool>` **can_sleep**
  215. +-----------+----------------------+
  216. | *Default* | ``true`` |
  217. +-----------+----------------------+
  218. | *Setter* | set_can_sleep(value) |
  219. +-----------+----------------------+
  220. | *Getter* | is_able_to_sleep() |
  221. +-----------+----------------------+
  222. If ``true``, the body can enter sleep mode when there is no movement. See :ref:`sleeping<class_RigidDynamicBody2D_property_sleeping>`.
  223. ----
  224. .. _class_RigidDynamicBody2D_property_center_of_mass:
  225. - :ref:`Vector2<class_Vector2>` **center_of_mass**
  226. +-----------+---------------------------+
  227. | *Default* | ``Vector2(0, 0)`` |
  228. +-----------+---------------------------+
  229. | *Setter* | set_center_of_mass(value) |
  230. +-----------+---------------------------+
  231. | *Getter* | get_center_of_mass() |
  232. +-----------+---------------------------+
  233. The body's custom center of mass, relative to the body's origin position, when :ref:`center_of_mass_mode<class_RigidDynamicBody2D_property_center_of_mass_mode>` is set to :ref:`CENTER_OF_MASS_MODE_CUSTOM<class_RigidDynamicBody2D_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.
  234. When :ref:`center_of_mass_mode<class_RigidDynamicBody2D_property_center_of_mass_mode>` is set to :ref:`CENTER_OF_MASS_MODE_AUTO<class_RigidDynamicBody2D_constant_CENTER_OF_MASS_MODE_AUTO>` (default value), the center of mass is automatically computed.
  235. ----
  236. .. _class_RigidDynamicBody2D_property_center_of_mass_mode:
  237. - :ref:`CenterOfMassMode<enum_RigidDynamicBody2D_CenterOfMassMode>` **center_of_mass_mode**
  238. +-----------+--------------------------------+
  239. | *Default* | ``0`` |
  240. +-----------+--------------------------------+
  241. | *Setter* | set_center_of_mass_mode(value) |
  242. +-----------+--------------------------------+
  243. | *Getter* | get_center_of_mass_mode() |
  244. +-----------+--------------------------------+
  245. Defines the way the body's center of mass is set. See :ref:`CenterOfMassMode<enum_RigidDynamicBody2D_CenterOfMassMode>` for possible values.
  246. ----
  247. .. _class_RigidDynamicBody2D_property_contact_monitor:
  248. - :ref:`bool<class_bool>` **contact_monitor**
  249. +-----------+------------------------------+
  250. | *Default* | ``false`` |
  251. +-----------+------------------------------+
  252. | *Setter* | set_contact_monitor(value) |
  253. +-----------+------------------------------+
  254. | *Getter* | is_contact_monitor_enabled() |
  255. +-----------+------------------------------+
  256. If ``true``, the body will emit signals when it collides with another RigidDynamicBody2D. See also :ref:`contacts_reported<class_RigidDynamicBody2D_property_contacts_reported>`.
  257. ----
  258. .. _class_RigidDynamicBody2D_property_contacts_reported:
  259. - :ref:`int<class_int>` **contacts_reported**
  260. +-----------+----------------------------------+
  261. | *Default* | ``0`` |
  262. +-----------+----------------------------------+
  263. | *Setter* | set_max_contacts_reported(value) |
  264. +-----------+----------------------------------+
  265. | *Getter* | get_max_contacts_reported() |
  266. +-----------+----------------------------------+
  267. The maximum number of contacts that will be recorded. Requires :ref:`contact_monitor<class_RigidDynamicBody2D_property_contact_monitor>` to be set to ``true``.
  268. **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).
  269. ----
  270. .. _class_RigidDynamicBody2D_property_continuous_cd:
  271. - :ref:`CCDMode<enum_RigidDynamicBody2D_CCDMode>` **continuous_cd**
  272. +-----------+------------------------------------------------+
  273. | *Default* | ``0`` |
  274. +-----------+------------------------------------------------+
  275. | *Setter* | set_continuous_collision_detection_mode(value) |
  276. +-----------+------------------------------------------------+
  277. | *Getter* | get_continuous_collision_detection_mode() |
  278. +-----------+------------------------------------------------+
  279. Continuous collision detection mode.
  280. 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_RigidDynamicBody2D_CCDMode>` for details.
  281. ----
  282. .. _class_RigidDynamicBody2D_property_custom_integrator:
  283. - :ref:`bool<class_bool>` **custom_integrator**
  284. +-----------+----------------------------------+
  285. | *Default* | ``false`` |
  286. +-----------+----------------------------------+
  287. | *Setter* | set_use_custom_integrator(value) |
  288. +-----------+----------------------------------+
  289. | *Getter* | is_using_custom_integrator() |
  290. +-----------+----------------------------------+
  291. If ``true``, internal force integration is disabled for this body. Aside from collision response, the body will only move as determined by the :ref:`_integrate_forces<class_RigidDynamicBody2D_method__integrate_forces>` function.
  292. ----
  293. .. _class_RigidDynamicBody2D_property_freeze:
  294. - :ref:`bool<class_bool>` **freeze**
  295. +-----------+---------------------------+
  296. | *Default* | ``false`` |
  297. +-----------+---------------------------+
  298. | *Setter* | set_freeze_enabled(value) |
  299. +-----------+---------------------------+
  300. | *Getter* | is_freeze_enabled() |
  301. +-----------+---------------------------+
  302. If ``true``, the body is frozen. Gravity and forces are not applied anymore.
  303. See :ref:`freeze_mode<class_RigidDynamicBody2D_property_freeze_mode>` to set the body's behavior when frozen.
  304. For a body that is always frozen, use :ref:`StaticBody2D<class_StaticBody2D>` or :ref:`AnimatableBody2D<class_AnimatableBody2D>` instead.
  305. ----
  306. .. _class_RigidDynamicBody2D_property_freeze_mode:
  307. - :ref:`FreezeMode<enum_RigidDynamicBody2D_FreezeMode>` **freeze_mode**
  308. +-----------+------------------------+
  309. | *Default* | ``0`` |
  310. +-----------+------------------------+
  311. | *Setter* | set_freeze_mode(value) |
  312. +-----------+------------------------+
  313. | *Getter* | get_freeze_mode() |
  314. +-----------+------------------------+
  315. The body's freeze mode. Can be used to set the body's behavior when :ref:`freeze<class_RigidDynamicBody2D_property_freeze>` is enabled. See :ref:`FreezeMode<enum_RigidDynamicBody2D_FreezeMode>` for possible values.
  316. For a body that is always frozen, use :ref:`StaticBody2D<class_StaticBody2D>` or :ref:`AnimatableBody2D<class_AnimatableBody2D>` instead.
  317. ----
  318. .. _class_RigidDynamicBody2D_property_gravity_scale:
  319. - :ref:`float<class_float>` **gravity_scale**
  320. +-----------+--------------------------+
  321. | *Default* | ``1.0`` |
  322. +-----------+--------------------------+
  323. | *Setter* | set_gravity_scale(value) |
  324. +-----------+--------------------------+
  325. | *Getter* | get_gravity_scale() |
  326. +-----------+--------------------------+
  327. Multiplies the gravity applied to the body. The body's gravity is calculated from the **Default Gravity** value in **Project > Project Settings > Physics > 2d** and/or any additional gravity vector applied by :ref:`Area2D<class_Area2D>`\ s.
  328. ----
  329. .. _class_RigidDynamicBody2D_property_inertia:
  330. - :ref:`float<class_float>` **inertia**
  331. +-----------+--------------------+
  332. | *Default* | ``0.0`` |
  333. +-----------+--------------------+
  334. | *Setter* | set_inertia(value) |
  335. +-----------+--------------------+
  336. | *Getter* | get_inertia() |
  337. +-----------+--------------------+
  338. 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.
  339. If set to ``0``, inertia is automatically computed (default value).
  340. ----
  341. .. _class_RigidDynamicBody2D_property_linear_damp:
  342. - :ref:`float<class_float>` **linear_damp**
  343. +-----------+------------------------+
  344. | *Default* | ``0.0`` |
  345. +-----------+------------------------+
  346. | *Setter* | set_linear_damp(value) |
  347. +-----------+------------------------+
  348. | *Getter* | get_linear_damp() |
  349. +-----------+------------------------+
  350. Damps the body's movement. By default, the body will use the **Default Linear Damp** in **Project > Project Settings > Physics > 2d** or any value override set by an :ref:`Area2D<class_Area2D>` the body is in. Depending on :ref:`linear_damp_mode<class_RigidDynamicBody2D_property_linear_damp_mode>`, you can set :ref:`linear_damp<class_RigidDynamicBody2D_property_linear_damp>` to be added to or to replace the body's damping value.
  351. See :ref:`ProjectSettings.physics/2d/default_linear_damp<class_ProjectSettings_property_physics/2d/default_linear_damp>` for more details about damping.
  352. ----
  353. .. _class_RigidDynamicBody2D_property_linear_damp_mode:
  354. - :ref:`DampMode<enum_RigidDynamicBody2D_DampMode>` **linear_damp_mode**
  355. +-----------+-----------------------------+
  356. | *Default* | ``0`` |
  357. +-----------+-----------------------------+
  358. | *Setter* | set_linear_damp_mode(value) |
  359. +-----------+-----------------------------+
  360. | *Getter* | get_linear_damp_mode() |
  361. +-----------+-----------------------------+
  362. Defines how :ref:`linear_damp<class_RigidDynamicBody2D_property_linear_damp>` is applied. See :ref:`DampMode<enum_RigidDynamicBody2D_DampMode>` for possible values.
  363. ----
  364. .. _class_RigidDynamicBody2D_property_linear_velocity:
  365. - :ref:`Vector2<class_Vector2>` **linear_velocity**
  366. +-----------+----------------------------+
  367. | *Default* | ``Vector2(0, 0)`` |
  368. +-----------+----------------------------+
  369. | *Setter* | set_linear_velocity(value) |
  370. +-----------+----------------------------+
  371. | *Getter* | get_linear_velocity() |
  372. +-----------+----------------------------+
  373. The body's linear velocity.
  374. ----
  375. .. _class_RigidDynamicBody2D_property_lock_rotation:
  376. - :ref:`bool<class_bool>` **lock_rotation**
  377. +-----------+----------------------------------+
  378. | *Default* | ``false`` |
  379. +-----------+----------------------------------+
  380. | *Setter* | set_lock_rotation_enabled(value) |
  381. +-----------+----------------------------------+
  382. | *Getter* | is_lock_rotation_enabled() |
  383. +-----------+----------------------------------+
  384. If ``true``, the body cannot rotate. Gravity and forces only apply linear movement.
  385. ----
  386. .. _class_RigidDynamicBody2D_property_mass:
  387. - :ref:`float<class_float>` **mass**
  388. +-----------+-----------------+
  389. | *Default* | ``1.0`` |
  390. +-----------+-----------------+
  391. | *Setter* | set_mass(value) |
  392. +-----------+-----------------+
  393. | *Getter* | get_mass() |
  394. +-----------+-----------------+
  395. The body's mass.
  396. ----
  397. .. _class_RigidDynamicBody2D_property_physics_material_override:
  398. - :ref:`PhysicsMaterial<class_PhysicsMaterial>` **physics_material_override**
  399. +----------+--------------------------------------+
  400. | *Setter* | set_physics_material_override(value) |
  401. +----------+--------------------------------------+
  402. | *Getter* | get_physics_material_override() |
  403. +----------+--------------------------------------+
  404. The physics material override for the body.
  405. If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one.
  406. ----
  407. .. _class_RigidDynamicBody2D_property_sleeping:
  408. - :ref:`bool<class_bool>` **sleeping**
  409. +-----------+---------------------+
  410. | *Default* | ``false`` |
  411. +-----------+---------------------+
  412. | *Setter* | set_sleeping(value) |
  413. +-----------+---------------------+
  414. | *Getter* | is_sleeping() |
  415. +-----------+---------------------+
  416. 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_RigidDynamicBody2D_method_apply_impulse>` or :ref:`add_force<class_RigidDynamicBody2D_method_add_force>` methods.
  417. Method Descriptions
  418. -------------------
  419. .. _class_RigidDynamicBody2D_method__integrate_forces:
  420. - void **_integrate_forces** **(** :ref:`PhysicsDirectBodyState2D<class_PhysicsDirectBodyState2D>` state **)** |virtual|
  421. Allows you to read and safely modify the simulation state for the object. Use this instead of :ref:`Node._physics_process<class_Node_method__physics_process>` if you need to directly change the body's ``position`` or other physics properties. By default, it works in addition to the usual physics behavior, but :ref:`custom_integrator<class_RigidDynamicBody2D_property_custom_integrator>` allows you to disable the default behavior and write custom force integration for a body.
  422. ----
  423. .. _class_RigidDynamicBody2D_method_add_central_force:
  424. - void **add_central_force** **(** :ref:`Vector2<class_Vector2>` force **)**
  425. Adds a constant directional force without affecting rotation.
  426. ----
  427. .. _class_RigidDynamicBody2D_method_add_force:
  428. - void **add_force** **(** :ref:`Vector2<class_Vector2>` force, :ref:`Vector2<class_Vector2>` position=Vector2(0, 0) **)**
  429. Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
  430. ----
  431. .. _class_RigidDynamicBody2D_method_add_torque:
  432. - void **add_torque** **(** :ref:`float<class_float>` torque **)**
  433. Adds a constant rotational force.
  434. ----
  435. .. _class_RigidDynamicBody2D_method_apply_central_impulse:
  436. - void **apply_central_impulse** **(** :ref:`Vector2<class_Vector2>` impulse=Vector2(0, 0) **)**
  437. Applies a directional impulse without affecting rotation.
  438. ----
  439. .. _class_RigidDynamicBody2D_method_apply_impulse:
  440. - void **apply_impulse** **(** :ref:`Vector2<class_Vector2>` impulse, :ref:`Vector2<class_Vector2>` position=Vector2(0, 0) **)**
  441. Applies a positioned impulse to the body. 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). The position uses the rotation of the global coordinate system, but is centered at the object's origin.
  442. ----
  443. .. _class_RigidDynamicBody2D_method_apply_torque_impulse:
  444. - void **apply_torque_impulse** **(** :ref:`float<class_float>` torque **)**
  445. Applies a rotational impulse to the body.
  446. ----
  447. .. _class_RigidDynamicBody2D_method_get_colliding_bodies:
  448. - :ref:`Node2D[]<class_Node2D>` **get_colliding_bodies** **(** **)** |const|
  449. Returns a list of the bodies colliding with this one. Requires :ref:`contact_monitor<class_RigidDynamicBody2D_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidDynamicBody2D_property_contacts_reported>` to be set high enough to detect all the collisions.
  450. **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.
  451. ----
  452. .. _class_RigidDynamicBody2D_method_set_axis_velocity:
  453. - void **set_axis_velocity** **(** :ref:`Vector2<class_Vector2>` axis_velocity **)**
  454. 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.
  455. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  456. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  457. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  458. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  459. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  460. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`