class_rigidbody2d.rst 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/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. A body that is controlled by the 2D physics engine.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This node implements simulated 2D physics. You do not control a RigidBody2D 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.
  15. A RigidBody2D has 4 behavior :ref:`mode<class_RigidBody2D_property_mode>`\ s: Rigid, Static, Character, and Kinematic.
  16. \ **Note:** You should not change a RigidBody2D'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_RigidBody2D_method__integrate_forces>`, which allows you to directly access the physics state.
  17. 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.
  18. 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_RigidBody2D_property_custom_integrator>`.
  19. The center of mass is always located at the node's origin without taking into account the :ref:`CollisionShape2D<class_CollisionShape2D>` centroid offsets.
  20. .. rst-class:: classref-introduction-group
  21. Tutorials
  22. ---------
  23. - `2D Physics Platformer Demo <https://godotengine.org/asset-library/asset/119>`__
  24. - `Instancing Demo <https://godotengine.org/asset-library/asset/148>`__
  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>` | ``-1.0`` |
  32. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  33. | :ref:`float<class_float>` | :ref:`angular_velocity<class_RigidBody2D_property_angular_velocity>` | ``0.0`` |
  34. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  35. | :ref:`Vector2<class_Vector2>` | :ref:`applied_force<class_RigidBody2D_property_applied_force>` | ``Vector2( 0, 0 )`` |
  36. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  37. | :ref:`float<class_float>` | :ref:`applied_torque<class_RigidBody2D_property_applied_torque>` | ``0.0`` |
  38. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  39. | :ref:`float<class_float>` | :ref:`bounce<class_RigidBody2D_property_bounce>` | |
  40. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  41. | :ref:`bool<class_bool>` | :ref:`can_sleep<class_RigidBody2D_property_can_sleep>` | ``true`` |
  42. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  43. | :ref:`bool<class_bool>` | :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` | ``false`` |
  44. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  45. | :ref:`int<class_int>` | :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>` | ``0`` |
  46. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  47. | :ref:`CCDMode<enum_RigidBody2D_CCDMode>` | :ref:`continuous_cd<class_RigidBody2D_property_continuous_cd>` | ``0`` |
  48. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  49. | :ref:`bool<class_bool>` | :ref:`custom_integrator<class_RigidBody2D_property_custom_integrator>` | ``false`` |
  50. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  51. | :ref:`float<class_float>` | :ref:`friction<class_RigidBody2D_property_friction>` | |
  52. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  53. | :ref:`float<class_float>` | :ref:`gravity_scale<class_RigidBody2D_property_gravity_scale>` | ``1.0`` |
  54. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  55. | :ref:`float<class_float>` | :ref:`inertia<class_RigidBody2D_property_inertia>` | |
  56. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  57. | :ref:`float<class_float>` | :ref:`linear_damp<class_RigidBody2D_property_linear_damp>` | ``-1.0`` |
  58. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  59. | :ref:`Vector2<class_Vector2>` | :ref:`linear_velocity<class_RigidBody2D_property_linear_velocity>` | ``Vector2( 0, 0 )`` |
  60. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  61. | :ref:`float<class_float>` | :ref:`mass<class_RigidBody2D_property_mass>` | ``1.0`` |
  62. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  63. | :ref:`Mode<enum_RigidBody2D_Mode>` | :ref:`mode<class_RigidBody2D_property_mode>` | ``0`` |
  64. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  65. | :ref:`PhysicsMaterial<class_PhysicsMaterial>` | :ref:`physics_material_override<class_RigidBody2D_property_physics_material_override>` | |
  66. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  67. | :ref:`bool<class_bool>` | :ref:`sleeping<class_RigidBody2D_property_sleeping>` | ``false`` |
  68. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  69. | :ref:`float<class_float>` | :ref:`weight<class_RigidBody2D_property_weight>` | ``9.8`` |
  70. +-----------------------------------------------+----------------------------------------------------------------------------------------+---------------------+
  71. .. rst-class:: classref-reftable-group
  72. Methods
  73. -------
  74. .. table::
  75. :widths: auto
  76. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`_integrate_forces<class_RigidBody2D_method__integrate_forces>` **(** :ref:`Physics2DDirectBodyState<class_Physics2DDirectBodyState>` state **)** |virtual| |
  78. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | void | :ref:`add_central_force<class_RigidBody2D_method_add_central_force>` **(** :ref:`Vector2<class_Vector2>` force **)** |
  80. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`add_force<class_RigidBody2D_method_add_force>` **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` force **)** |
  82. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | void | :ref:`add_torque<class_RigidBody2D_method_add_torque>` **(** :ref:`float<class_float>` torque **)** |
  84. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`apply_central_impulse<class_RigidBody2D_method_apply_central_impulse>` **(** :ref:`Vector2<class_Vector2>` impulse **)** |
  86. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`apply_impulse<class_RigidBody2D_method_apply_impulse>` **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` impulse **)** |
  88. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`apply_torque_impulse<class_RigidBody2D_method_apply_torque_impulse>` **(** :ref:`float<class_float>` torque **)** |
  90. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Array<class_Array>` | :ref:`get_colliding_bodies<class_RigidBody2D_method_get_colliding_bodies>` **(** **)** |const| |
  92. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | void | :ref:`set_axis_velocity<class_RigidBody2D_method_set_axis_velocity>` **(** :ref:`Vector2<class_Vector2>` axis_velocity **)** |
  94. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`bool<class_bool>` | :ref:`test_motion<class_RigidBody2D_method_test_motion>` **(** :ref:`Vector2<class_Vector2>` motion, :ref:`bool<class_bool>` infinite_inertia=true, :ref:`float<class_float>` margin=0.08, :ref:`Physics2DTestMotionResult<class_Physics2DTestMotionResult>` result=null **)** |
  96. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. .. rst-class:: classref-section-separator
  98. ----
  99. .. rst-class:: classref-descriptions-group
  100. Signals
  101. -------
  102. .. _class_RigidBody2D_signal_body_entered:
  103. .. rst-class:: classref-signal
  104. **body_entered** **(** :ref:`Node<class_Node>` body **)**
  105. 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:`contacts_reported<class_RigidBody2D_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.
  106. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_RigidBody2D_signal_body_exited:
  110. .. rst-class:: classref-signal
  111. **body_exited** **(** :ref:`Node<class_Node>` body **)**
  112. 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:`contacts_reported<class_RigidBody2D_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.
  113. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  114. .. rst-class:: classref-item-separator
  115. ----
  116. .. _class_RigidBody2D_signal_body_shape_entered:
  117. .. rst-class:: classref-signal
  118. **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 **)**
  119. 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:`contacts_reported<class_RigidBody2D_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.
  120. \ ``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:`Physics2DServer<class_Physics2DServer>`.
  121. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  122. \ ``body_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  123. \ ``local_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of this RigidBody2D.
  124. \ **Example of getting the** :ref:`CollisionShape2D<class_CollisionShape2D>` **node from the shape index:**\
  125. ::
  126. var body_shape_owner = body.shape_find_owner(body_shape_index)
  127. var body_shape_node = body.shape_owner_get_owner(body_shape_owner)
  128. var local_shape_owner = shape_find_owner(local_shape_index)
  129. var local_shape_node = shape_owner_get_owner(local_shape_owner)
  130. .. rst-class:: classref-item-separator
  131. ----
  132. .. _class_RigidBody2D_signal_body_shape_exited:
  133. .. rst-class:: classref-signal
  134. **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 **)**
  135. 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:`contacts_reported<class_RigidBody2D_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.
  136. \ ``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:`Physics2DServer<class_Physics2DServer>`.
  137. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  138. \ ``body_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  139. \ ``local_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of this RigidBody2D.
  140. See also :ref:`body_shape_entered<class_RigidBody2D_signal_body_shape_entered>`.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_RigidBody2D_signal_sleeping_state_changed:
  144. .. rst-class:: classref-signal
  145. **sleeping_state_changed** **(** **)**
  146. Emitted when the physics engine changes the body's sleeping state.
  147. \ **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.
  148. .. rst-class:: classref-section-separator
  149. ----
  150. .. rst-class:: classref-descriptions-group
  151. Enumerations
  152. ------------
  153. .. _enum_RigidBody2D_Mode:
  154. .. rst-class:: classref-enumeration
  155. enum **Mode**:
  156. .. _class_RigidBody2D_constant_MODE_RIGID:
  157. .. rst-class:: classref-enumeration-constant
  158. :ref:`Mode<enum_RigidBody2D_Mode>` **MODE_RIGID** = ``0``
  159. Rigid mode. The body behaves as a physical object. It collides with other bodies and responds to forces applied to it. This is the default mode.
  160. .. _class_RigidBody2D_constant_MODE_STATIC:
  161. .. rst-class:: classref-enumeration-constant
  162. :ref:`Mode<enum_RigidBody2D_Mode>` **MODE_STATIC** = ``1``
  163. Static mode. The body behaves like a :ref:`StaticBody2D<class_StaticBody2D>` and does not move.
  164. .. _class_RigidBody2D_constant_MODE_CHARACTER:
  165. .. rst-class:: classref-enumeration-constant
  166. :ref:`Mode<enum_RigidBody2D_Mode>` **MODE_CHARACTER** = ``2``
  167. Character mode. Similar to :ref:`MODE_RIGID<class_RigidBody2D_constant_MODE_RIGID>`, but the body can not rotate.
  168. .. _class_RigidBody2D_constant_MODE_KINEMATIC:
  169. .. rst-class:: classref-enumeration-constant
  170. :ref:`Mode<enum_RigidBody2D_Mode>` **MODE_KINEMATIC** = ``3``
  171. Kinematic mode. The body behaves like a :ref:`KinematicBody2D<class_KinematicBody2D>`, and must be moved by code.
  172. .. rst-class:: classref-item-separator
  173. ----
  174. .. _enum_RigidBody2D_CCDMode:
  175. .. rst-class:: classref-enumeration
  176. enum **CCDMode**:
  177. .. _class_RigidBody2D_constant_CCD_MODE_DISABLED:
  178. .. rst-class:: classref-enumeration-constant
  179. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_DISABLED** = ``0``
  180. Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
  181. .. _class_RigidBody2D_constant_CCD_MODE_CAST_RAY:
  182. .. rst-class:: classref-enumeration-constant
  183. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_CAST_RAY** = ``1``
  184. Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise.
  185. .. _class_RigidBody2D_constant_CCD_MODE_CAST_SHAPE:
  186. .. rst-class:: classref-enumeration-constant
  187. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_CAST_SHAPE** = ``2``
  188. Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise.
  189. .. rst-class:: classref-section-separator
  190. ----
  191. .. rst-class:: classref-descriptions-group
  192. Property Descriptions
  193. ---------------------
  194. .. _class_RigidBody2D_property_angular_damp:
  195. .. rst-class:: classref-property
  196. :ref:`float<class_float>` **angular_damp** = ``-1.0``
  197. .. rst-class:: classref-property-setget
  198. - void **set_angular_damp** **(** :ref:`float<class_float>` value **)**
  199. - :ref:`float<class_float>` **get_angular_damp** **(** **)**
  200. Damps the body's :ref:`angular_velocity<class_RigidBody2D_property_angular_velocity>`. If ``-1``, the body will use the **Default Angular Damp** defined in **Project > Project Settings > Physics > 2d**. If greater than ``-1`` it will be added to the default project value.
  201. See :ref:`ProjectSettings.physics/2d/default_angular_damp<class_ProjectSettings_property_physics/2d/default_angular_damp>` for more details about damping.
  202. .. rst-class:: classref-item-separator
  203. ----
  204. .. _class_RigidBody2D_property_angular_velocity:
  205. .. rst-class:: classref-property
  206. :ref:`float<class_float>` **angular_velocity** = ``0.0``
  207. .. rst-class:: classref-property-setget
  208. - void **set_angular_velocity** **(** :ref:`float<class_float>` value **)**
  209. - :ref:`float<class_float>` **get_angular_velocity** **(** **)**
  210. The body's rotational velocity in *radians* per second.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_RigidBody2D_property_applied_force:
  214. .. rst-class:: classref-property
  215. :ref:`Vector2<class_Vector2>` **applied_force** = ``Vector2( 0, 0 )``
  216. .. rst-class:: classref-property-setget
  217. - void **set_applied_force** **(** :ref:`Vector2<class_Vector2>` value **)**
  218. - :ref:`Vector2<class_Vector2>` **get_applied_force** **(** **)**
  219. The body's total applied force.
  220. .. rst-class:: classref-item-separator
  221. ----
  222. .. _class_RigidBody2D_property_applied_torque:
  223. .. rst-class:: classref-property
  224. :ref:`float<class_float>` **applied_torque** = ``0.0``
  225. .. rst-class:: classref-property-setget
  226. - void **set_applied_torque** **(** :ref:`float<class_float>` value **)**
  227. - :ref:`float<class_float>` **get_applied_torque** **(** **)**
  228. The body's total applied torque.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_RigidBody2D_property_bounce:
  232. .. rst-class:: classref-property
  233. :ref:`float<class_float>` **bounce**
  234. .. rst-class:: classref-property-setget
  235. - void **set_bounce** **(** :ref:`float<class_float>` value **)**
  236. - :ref:`float<class_float>` **get_bounce** **(** **)**
  237. The body's bounciness. Values range from ``0`` (no bounce) to ``1`` (full bounciness).
  238. Deprecated, use :ref:`PhysicsMaterial.bounce<class_PhysicsMaterial_property_bounce>` instead via :ref:`physics_material_override<class_RigidBody2D_property_physics_material_override>`.
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_RigidBody2D_property_can_sleep:
  242. .. rst-class:: classref-property
  243. :ref:`bool<class_bool>` **can_sleep** = ``true``
  244. .. rst-class:: classref-property-setget
  245. - void **set_can_sleep** **(** :ref:`bool<class_bool>` value **)**
  246. - :ref:`bool<class_bool>` **is_able_to_sleep** **(** **)**
  247. If ``true``, the body can enter sleep mode when there is no movement. See :ref:`sleeping<class_RigidBody2D_property_sleeping>`.
  248. \ **Note:** A RigidBody2D will never enter sleep mode automatically if its :ref:`mode<class_RigidBody2D_property_mode>` is :ref:`MODE_CHARACTER<class_RigidBody2D_constant_MODE_CHARACTER>`. It can still be put to sleep manually by setting its :ref:`sleeping<class_RigidBody2D_property_sleeping>` property to ``true``.
  249. .. rst-class:: classref-item-separator
  250. ----
  251. .. _class_RigidBody2D_property_contact_monitor:
  252. .. rst-class:: classref-property
  253. :ref:`bool<class_bool>` **contact_monitor** = ``false``
  254. .. rst-class:: classref-property-setget
  255. - void **set_contact_monitor** **(** :ref:`bool<class_bool>` value **)**
  256. - :ref:`bool<class_bool>` **is_contact_monitor_enabled** **(** **)**
  257. If ``true``, the body will emit signals when it collides with another RigidBody2D. See also :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>`.
  258. .. rst-class:: classref-item-separator
  259. ----
  260. .. _class_RigidBody2D_property_contacts_reported:
  261. .. rst-class:: classref-property
  262. :ref:`int<class_int>` **contacts_reported** = ``0``
  263. .. rst-class:: classref-property-setget
  264. - void **set_max_contacts_reported** **(** :ref:`int<class_int>` value **)**
  265. - :ref:`int<class_int>` **get_max_contacts_reported** **(** **)**
  266. The maximum number of contacts that will be recorded. Requires :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to be set to ``true``.
  267. \ **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).
  268. .. rst-class:: classref-item-separator
  269. ----
  270. .. _class_RigidBody2D_property_continuous_cd:
  271. .. rst-class:: classref-property
  272. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **continuous_cd** = ``0``
  273. .. rst-class:: classref-property-setget
  274. - void **set_continuous_collision_detection_mode** **(** :ref:`CCDMode<enum_RigidBody2D_CCDMode>` value **)**
  275. - :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **get_continuous_collision_detection_mode** **(** **)**
  276. Continuous collision detection mode.
  277. 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.
  278. .. rst-class:: classref-item-separator
  279. ----
  280. .. _class_RigidBody2D_property_custom_integrator:
  281. .. rst-class:: classref-property
  282. :ref:`bool<class_bool>` **custom_integrator** = ``false``
  283. .. rst-class:: classref-property-setget
  284. - void **set_use_custom_integrator** **(** :ref:`bool<class_bool>` value **)**
  285. - :ref:`bool<class_bool>` **is_using_custom_integrator** **(** **)**
  286. 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_RigidBody2D_method__integrate_forces>` function.
  287. .. rst-class:: classref-item-separator
  288. ----
  289. .. _class_RigidBody2D_property_friction:
  290. .. rst-class:: classref-property
  291. :ref:`float<class_float>` **friction**
  292. .. rst-class:: classref-property-setget
  293. - void **set_friction** **(** :ref:`float<class_float>` value **)**
  294. - :ref:`float<class_float>` **get_friction** **(** **)**
  295. The body's friction. Values range from ``0`` (frictionless) to ``1`` (maximum friction).
  296. Deprecated, use :ref:`PhysicsMaterial.friction<class_PhysicsMaterial_property_friction>` instead via :ref:`physics_material_override<class_RigidBody2D_property_physics_material_override>`.
  297. .. rst-class:: classref-item-separator
  298. ----
  299. .. _class_RigidBody2D_property_gravity_scale:
  300. .. rst-class:: classref-property
  301. :ref:`float<class_float>` **gravity_scale** = ``1.0``
  302. .. rst-class:: classref-property-setget
  303. - void **set_gravity_scale** **(** :ref:`float<class_float>` value **)**
  304. - :ref:`float<class_float>` **get_gravity_scale** **(** **)**
  305. 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.
  306. .. rst-class:: classref-item-separator
  307. ----
  308. .. _class_RigidBody2D_property_inertia:
  309. .. rst-class:: classref-property
  310. :ref:`float<class_float>` **inertia**
  311. .. rst-class:: classref-property-setget
  312. - void **set_inertia** **(** :ref:`float<class_float>` value **)**
  313. - :ref:`float<class_float>` **get_inertia** **(** **)**
  314. 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 function allows you to set a custom value. Set 0 inertia to return to automatically computing it.
  315. .. rst-class:: classref-item-separator
  316. ----
  317. .. _class_RigidBody2D_property_linear_damp:
  318. .. rst-class:: classref-property
  319. :ref:`float<class_float>` **linear_damp** = ``-1.0``
  320. .. rst-class:: classref-property-setget
  321. - void **set_linear_damp** **(** :ref:`float<class_float>` value **)**
  322. - :ref:`float<class_float>` **get_linear_damp** **(** **)**
  323. Damps the body's :ref:`linear_velocity<class_RigidBody2D_property_linear_velocity>`. If ``-1``, the body will use the **Default Linear Damp** in **Project > Project Settings > Physics > 2d**. If greater than ``-1`` it will be added to the default project value.
  324. See :ref:`ProjectSettings.physics/2d/default_linear_damp<class_ProjectSettings_property_physics/2d/default_linear_damp>` for more details about damping.
  325. .. rst-class:: classref-item-separator
  326. ----
  327. .. _class_RigidBody2D_property_linear_velocity:
  328. .. rst-class:: classref-property
  329. :ref:`Vector2<class_Vector2>` **linear_velocity** = ``Vector2( 0, 0 )``
  330. .. rst-class:: classref-property-setget
  331. - void **set_linear_velocity** **(** :ref:`Vector2<class_Vector2>` value **)**
  332. - :ref:`Vector2<class_Vector2>` **get_linear_velocity** **(** **)**
  333. 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_method__integrate_forces>` as your process loop for precise control of the body state.
  334. .. rst-class:: classref-item-separator
  335. ----
  336. .. _class_RigidBody2D_property_mass:
  337. .. rst-class:: classref-property
  338. :ref:`float<class_float>` **mass** = ``1.0``
  339. .. rst-class:: classref-property-setget
  340. - void **set_mass** **(** :ref:`float<class_float>` value **)**
  341. - :ref:`float<class_float>` **get_mass** **(** **)**
  342. The body's mass.
  343. .. rst-class:: classref-item-separator
  344. ----
  345. .. _class_RigidBody2D_property_mode:
  346. .. rst-class:: classref-property
  347. :ref:`Mode<enum_RigidBody2D_Mode>` **mode** = ``0``
  348. .. rst-class:: classref-property-setget
  349. - void **set_mode** **(** :ref:`Mode<enum_RigidBody2D_Mode>` value **)**
  350. - :ref:`Mode<enum_RigidBody2D_Mode>` **get_mode** **(** **)**
  351. The body's mode. See :ref:`Mode<enum_RigidBody2D_Mode>` for possible values.
  352. .. rst-class:: classref-item-separator
  353. ----
  354. .. _class_RigidBody2D_property_physics_material_override:
  355. .. rst-class:: classref-property
  356. :ref:`PhysicsMaterial<class_PhysicsMaterial>` **physics_material_override**
  357. .. rst-class:: classref-property-setget
  358. - void **set_physics_material_override** **(** :ref:`PhysicsMaterial<class_PhysicsMaterial>` value **)**
  359. - :ref:`PhysicsMaterial<class_PhysicsMaterial>` **get_physics_material_override** **(** **)**
  360. The physics material override for the body.
  361. If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one.
  362. .. rst-class:: classref-item-separator
  363. ----
  364. .. _class_RigidBody2D_property_sleeping:
  365. .. rst-class:: classref-property
  366. :ref:`bool<class_bool>` **sleeping** = ``false``
  367. .. rst-class:: classref-property-setget
  368. - void **set_sleeping** **(** :ref:`bool<class_bool>` value **)**
  369. - :ref:`bool<class_bool>` **is_sleeping** **(** **)**
  370. 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:`add_force<class_RigidBody2D_method_add_force>` methods.
  371. .. rst-class:: classref-item-separator
  372. ----
  373. .. _class_RigidBody2D_property_weight:
  374. .. rst-class:: classref-property
  375. :ref:`float<class_float>` **weight** = ``9.8``
  376. .. rst-class:: classref-property-setget
  377. - void **set_weight** **(** :ref:`float<class_float>` value **)**
  378. - :ref:`float<class_float>` **get_weight** **(** **)**
  379. The body's weight based on its mass and the **Default Gravity** value in **Project > Project Settings > Physics > 2d**.
  380. .. rst-class:: classref-section-separator
  381. ----
  382. .. rst-class:: classref-descriptions-group
  383. Method Descriptions
  384. -------------------
  385. .. _class_RigidBody2D_method__integrate_forces:
  386. .. rst-class:: classref-method
  387. void **_integrate_forces** **(** :ref:`Physics2DDirectBodyState<class_Physics2DDirectBodyState>` state **)** |virtual|
  388. 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_RigidBody2D_property_custom_integrator>` allows you to disable the default behavior and write custom force integration for a body.
  389. .. rst-class:: classref-item-separator
  390. ----
  391. .. _class_RigidBody2D_method_add_central_force:
  392. .. rst-class:: classref-method
  393. void **add_central_force** **(** :ref:`Vector2<class_Vector2>` force **)**
  394. Adds a constant directional force without affecting rotation.
  395. .. rst-class:: classref-item-separator
  396. ----
  397. .. _class_RigidBody2D_method_add_force:
  398. .. rst-class:: classref-method
  399. void **add_force** **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` force **)**
  400. Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
  401. .. rst-class:: classref-item-separator
  402. ----
  403. .. _class_RigidBody2D_method_add_torque:
  404. .. rst-class:: classref-method
  405. void **add_torque** **(** :ref:`float<class_float>` torque **)**
  406. Adds a constant rotational force.
  407. .. rst-class:: classref-item-separator
  408. ----
  409. .. _class_RigidBody2D_method_apply_central_impulse:
  410. .. rst-class:: classref-method
  411. void **apply_central_impulse** **(** :ref:`Vector2<class_Vector2>` impulse **)**
  412. Applies a directional impulse without affecting rotation.
  413. .. rst-class:: classref-item-separator
  414. ----
  415. .. _class_RigidBody2D_method_apply_impulse:
  416. .. rst-class:: classref-method
  417. void **apply_impulse** **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` impulse **)**
  418. 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.
  419. .. rst-class:: classref-item-separator
  420. ----
  421. .. _class_RigidBody2D_method_apply_torque_impulse:
  422. .. rst-class:: classref-method
  423. void **apply_torque_impulse** **(** :ref:`float<class_float>` torque **)**
  424. Applies a rotational impulse to the body.
  425. .. rst-class:: classref-item-separator
  426. ----
  427. .. _class_RigidBody2D_method_get_colliding_bodies:
  428. .. rst-class:: classref-method
  429. :ref:`Array<class_Array>` **get_colliding_bodies** **(** **)** |const|
  430. 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:`contacts_reported<class_RigidBody2D_property_contacts_reported>` to be set high enough to detect all the collisions.
  431. \ **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.
  432. .. rst-class:: classref-item-separator
  433. ----
  434. .. _class_RigidBody2D_method_set_axis_velocity:
  435. .. rst-class:: classref-method
  436. void **set_axis_velocity** **(** :ref:`Vector2<class_Vector2>` axis_velocity **)**
  437. 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.
  438. .. rst-class:: classref-item-separator
  439. ----
  440. .. _class_RigidBody2D_method_test_motion:
  441. .. rst-class:: classref-method
  442. :ref:`bool<class_bool>` **test_motion** **(** :ref:`Vector2<class_Vector2>` motion, :ref:`bool<class_bool>` infinite_inertia=true, :ref:`float<class_float>` margin=0.08, :ref:`Physics2DTestMotionResult<class_Physics2DTestMotionResult>` result=null **)**
  443. Returns ``true`` if a collision would result from moving in the given vector. ``margin`` increases the size of the shapes involved in the collision detection, and ``result`` is an object of type :ref:`Physics2DTestMotionResult<class_Physics2DTestMotionResult>`, which contains additional information about the collision (should there be one).
  444. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  445. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  446. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  447. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`