class_rigidbody2d.rst 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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.5/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.5/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>` used by the :ref:`Physics2DServer<class_Physics2DServer>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``body.shape_owner_get_owner(body_shape_index)``.
  123. \ ``local_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of this RigidBody2D used by the :ref:`Physics2DServer<class_Physics2DServer>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``self.shape_owner_get_owner(local_shape_index)``.
  124. .. rst-class:: classref-item-separator
  125. ----
  126. .. _class_RigidBody2D_signal_body_shape_exited:
  127. .. rst-class:: classref-signal
  128. **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 **)**
  129. 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.
  130. \ ``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>`.
  131. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody2D<class_PhysicsBody2D>` or :ref:`TileMap<class_TileMap>`.
  132. \ ``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:`Physics2DServer<class_Physics2DServer>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``body.shape_owner_get_owner(body_shape_index)``.
  133. \ ``local_shape_index`` the index of the :ref:`Shape2D<class_Shape2D>` of this RigidBody2D used by the :ref:`Physics2DServer<class_Physics2DServer>`. Get the :ref:`CollisionShape2D<class_CollisionShape2D>` node with ``self.shape_owner_get_owner(local_shape_index)``.
  134. .. rst-class:: classref-item-separator
  135. ----
  136. .. _class_RigidBody2D_signal_sleeping_state_changed:
  137. .. rst-class:: classref-signal
  138. **sleeping_state_changed** **(** **)**
  139. Emitted when the physics engine changes the body's sleeping state.
  140. \ **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.
  141. .. rst-class:: classref-section-separator
  142. ----
  143. .. rst-class:: classref-descriptions-group
  144. Enumerations
  145. ------------
  146. .. _enum_RigidBody2D_Mode:
  147. .. rst-class:: classref-enumeration
  148. enum **Mode**:
  149. .. _class_RigidBody2D_constant_MODE_RIGID:
  150. .. rst-class:: classref-enumeration-constant
  151. :ref:`Mode<enum_RigidBody2D_Mode>` **MODE_RIGID** = ``0``
  152. 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.
  153. .. _class_RigidBody2D_constant_MODE_STATIC:
  154. .. rst-class:: classref-enumeration-constant
  155. :ref:`Mode<enum_RigidBody2D_Mode>` **MODE_STATIC** = ``1``
  156. Static mode. The body behaves like a :ref:`StaticBody2D<class_StaticBody2D>` and does not move.
  157. .. _class_RigidBody2D_constant_MODE_CHARACTER:
  158. .. rst-class:: classref-enumeration-constant
  159. :ref:`Mode<enum_RigidBody2D_Mode>` **MODE_CHARACTER** = ``2``
  160. Character mode. Similar to :ref:`MODE_RIGID<class_RigidBody2D_constant_MODE_RIGID>`, but the body can not rotate.
  161. .. _class_RigidBody2D_constant_MODE_KINEMATIC:
  162. .. rst-class:: classref-enumeration-constant
  163. :ref:`Mode<enum_RigidBody2D_Mode>` **MODE_KINEMATIC** = ``3``
  164. Kinematic mode. The body behaves like a :ref:`KinematicBody2D<class_KinematicBody2D>`, and must be moved by code.
  165. .. rst-class:: classref-item-separator
  166. ----
  167. .. _enum_RigidBody2D_CCDMode:
  168. .. rst-class:: classref-enumeration
  169. enum **CCDMode**:
  170. .. _class_RigidBody2D_constant_CCD_MODE_DISABLED:
  171. .. rst-class:: classref-enumeration-constant
  172. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_DISABLED** = ``0``
  173. Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
  174. .. _class_RigidBody2D_constant_CCD_MODE_CAST_RAY:
  175. .. rst-class:: classref-enumeration-constant
  176. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_CAST_RAY** = ``1``
  177. Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise.
  178. .. _class_RigidBody2D_constant_CCD_MODE_CAST_SHAPE:
  179. .. rst-class:: classref-enumeration-constant
  180. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **CCD_MODE_CAST_SHAPE** = ``2``
  181. Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise.
  182. .. rst-class:: classref-section-separator
  183. ----
  184. .. rst-class:: classref-descriptions-group
  185. Property Descriptions
  186. ---------------------
  187. .. _class_RigidBody2D_property_angular_damp:
  188. .. rst-class:: classref-property
  189. :ref:`float<class_float>` **angular_damp** = ``-1.0``
  190. .. rst-class:: classref-property-setget
  191. - void **set_angular_damp** **(** :ref:`float<class_float>` value **)**
  192. - :ref:`float<class_float>` **get_angular_damp** **(** **)**
  193. 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.
  194. See :ref:`ProjectSettings.physics/2d/default_angular_damp<class_ProjectSettings_property_physics/2d/default_angular_damp>` for more details about damping.
  195. .. rst-class:: classref-item-separator
  196. ----
  197. .. _class_RigidBody2D_property_angular_velocity:
  198. .. rst-class:: classref-property
  199. :ref:`float<class_float>` **angular_velocity** = ``0.0``
  200. .. rst-class:: classref-property-setget
  201. - void **set_angular_velocity** **(** :ref:`float<class_float>` value **)**
  202. - :ref:`float<class_float>` **get_angular_velocity** **(** **)**
  203. The body's rotational velocity in *radians* per second.
  204. .. rst-class:: classref-item-separator
  205. ----
  206. .. _class_RigidBody2D_property_applied_force:
  207. .. rst-class:: classref-property
  208. :ref:`Vector2<class_Vector2>` **applied_force** = ``Vector2( 0, 0 )``
  209. .. rst-class:: classref-property-setget
  210. - void **set_applied_force** **(** :ref:`Vector2<class_Vector2>` value **)**
  211. - :ref:`Vector2<class_Vector2>` **get_applied_force** **(** **)**
  212. The body's total applied force.
  213. .. rst-class:: classref-item-separator
  214. ----
  215. .. _class_RigidBody2D_property_applied_torque:
  216. .. rst-class:: classref-property
  217. :ref:`float<class_float>` **applied_torque** = ``0.0``
  218. .. rst-class:: classref-property-setget
  219. - void **set_applied_torque** **(** :ref:`float<class_float>` value **)**
  220. - :ref:`float<class_float>` **get_applied_torque** **(** **)**
  221. The body's total applied torque.
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_RigidBody2D_property_bounce:
  225. .. rst-class:: classref-property
  226. :ref:`float<class_float>` **bounce**
  227. .. rst-class:: classref-property-setget
  228. - void **set_bounce** **(** :ref:`float<class_float>` value **)**
  229. - :ref:`float<class_float>` **get_bounce** **(** **)**
  230. The body's bounciness. Values range from ``0`` (no bounce) to ``1`` (full bounciness).
  231. Deprecated, use :ref:`PhysicsMaterial.bounce<class_PhysicsMaterial_property_bounce>` instead via :ref:`physics_material_override<class_RigidBody2D_property_physics_material_override>`.
  232. .. rst-class:: classref-item-separator
  233. ----
  234. .. _class_RigidBody2D_property_can_sleep:
  235. .. rst-class:: classref-property
  236. :ref:`bool<class_bool>` **can_sleep** = ``true``
  237. .. rst-class:: classref-property-setget
  238. - void **set_can_sleep** **(** :ref:`bool<class_bool>` value **)**
  239. - :ref:`bool<class_bool>` **is_able_to_sleep** **(** **)**
  240. If ``true``, the body can enter sleep mode when there is no movement. See :ref:`sleeping<class_RigidBody2D_property_sleeping>`.
  241. \ **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``.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_RigidBody2D_property_contact_monitor:
  245. .. rst-class:: classref-property
  246. :ref:`bool<class_bool>` **contact_monitor** = ``false``
  247. .. rst-class:: classref-property-setget
  248. - void **set_contact_monitor** **(** :ref:`bool<class_bool>` value **)**
  249. - :ref:`bool<class_bool>` **is_contact_monitor_enabled** **(** **)**
  250. If ``true``, the body will emit signals when it collides with another RigidBody2D. See also :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>`.
  251. .. rst-class:: classref-item-separator
  252. ----
  253. .. _class_RigidBody2D_property_contacts_reported:
  254. .. rst-class:: classref-property
  255. :ref:`int<class_int>` **contacts_reported** = ``0``
  256. .. rst-class:: classref-property-setget
  257. - void **set_max_contacts_reported** **(** :ref:`int<class_int>` value **)**
  258. - :ref:`int<class_int>` **get_max_contacts_reported** **(** **)**
  259. The maximum number of contacts that will be recorded. Requires :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to be set to ``true``.
  260. \ **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).
  261. .. rst-class:: classref-item-separator
  262. ----
  263. .. _class_RigidBody2D_property_continuous_cd:
  264. .. rst-class:: classref-property
  265. :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **continuous_cd** = ``0``
  266. .. rst-class:: classref-property-setget
  267. - void **set_continuous_collision_detection_mode** **(** :ref:`CCDMode<enum_RigidBody2D_CCDMode>` value **)**
  268. - :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **get_continuous_collision_detection_mode** **(** **)**
  269. Continuous collision detection mode.
  270. 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.
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_RigidBody2D_property_custom_integrator:
  274. .. rst-class:: classref-property
  275. :ref:`bool<class_bool>` **custom_integrator** = ``false``
  276. .. rst-class:: classref-property-setget
  277. - void **set_use_custom_integrator** **(** :ref:`bool<class_bool>` value **)**
  278. - :ref:`bool<class_bool>` **is_using_custom_integrator** **(** **)**
  279. 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.
  280. .. rst-class:: classref-item-separator
  281. ----
  282. .. _class_RigidBody2D_property_friction:
  283. .. rst-class:: classref-property
  284. :ref:`float<class_float>` **friction**
  285. .. rst-class:: classref-property-setget
  286. - void **set_friction** **(** :ref:`float<class_float>` value **)**
  287. - :ref:`float<class_float>` **get_friction** **(** **)**
  288. The body's friction. Values range from ``0`` (frictionless) to ``1`` (maximum friction).
  289. Deprecated, use :ref:`PhysicsMaterial.friction<class_PhysicsMaterial_property_friction>` instead via :ref:`physics_material_override<class_RigidBody2D_property_physics_material_override>`.
  290. .. rst-class:: classref-item-separator
  291. ----
  292. .. _class_RigidBody2D_property_gravity_scale:
  293. .. rst-class:: classref-property
  294. :ref:`float<class_float>` **gravity_scale** = ``1.0``
  295. .. rst-class:: classref-property-setget
  296. - void **set_gravity_scale** **(** :ref:`float<class_float>` value **)**
  297. - :ref:`float<class_float>` **get_gravity_scale** **(** **)**
  298. 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.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_RigidBody2D_property_inertia:
  302. .. rst-class:: classref-property
  303. :ref:`float<class_float>` **inertia**
  304. .. rst-class:: classref-property-setget
  305. - void **set_inertia** **(** :ref:`float<class_float>` value **)**
  306. - :ref:`float<class_float>` **get_inertia** **(** **)**
  307. 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.
  308. .. rst-class:: classref-item-separator
  309. ----
  310. .. _class_RigidBody2D_property_linear_damp:
  311. .. rst-class:: classref-property
  312. :ref:`float<class_float>` **linear_damp** = ``-1.0``
  313. .. rst-class:: classref-property-setget
  314. - void **set_linear_damp** **(** :ref:`float<class_float>` value **)**
  315. - :ref:`float<class_float>` **get_linear_damp** **(** **)**
  316. 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.
  317. See :ref:`ProjectSettings.physics/2d/default_linear_damp<class_ProjectSettings_property_physics/2d/default_linear_damp>` for more details about damping.
  318. .. rst-class:: classref-item-separator
  319. ----
  320. .. _class_RigidBody2D_property_linear_velocity:
  321. .. rst-class:: classref-property
  322. :ref:`Vector2<class_Vector2>` **linear_velocity** = ``Vector2( 0, 0 )``
  323. .. rst-class:: classref-property-setget
  324. - void **set_linear_velocity** **(** :ref:`Vector2<class_Vector2>` value **)**
  325. - :ref:`Vector2<class_Vector2>` **get_linear_velocity** **(** **)**
  326. 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.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_RigidBody2D_property_mass:
  330. .. rst-class:: classref-property
  331. :ref:`float<class_float>` **mass** = ``1.0``
  332. .. rst-class:: classref-property-setget
  333. - void **set_mass** **(** :ref:`float<class_float>` value **)**
  334. - :ref:`float<class_float>` **get_mass** **(** **)**
  335. The body's mass.
  336. .. rst-class:: classref-item-separator
  337. ----
  338. .. _class_RigidBody2D_property_mode:
  339. .. rst-class:: classref-property
  340. :ref:`Mode<enum_RigidBody2D_Mode>` **mode** = ``0``
  341. .. rst-class:: classref-property-setget
  342. - void **set_mode** **(** :ref:`Mode<enum_RigidBody2D_Mode>` value **)**
  343. - :ref:`Mode<enum_RigidBody2D_Mode>` **get_mode** **(** **)**
  344. The body's mode. See :ref:`Mode<enum_RigidBody2D_Mode>` for possible values.
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _class_RigidBody2D_property_physics_material_override:
  348. .. rst-class:: classref-property
  349. :ref:`PhysicsMaterial<class_PhysicsMaterial>` **physics_material_override**
  350. .. rst-class:: classref-property-setget
  351. - void **set_physics_material_override** **(** :ref:`PhysicsMaterial<class_PhysicsMaterial>` value **)**
  352. - :ref:`PhysicsMaterial<class_PhysicsMaterial>` **get_physics_material_override** **(** **)**
  353. The physics material override for the body.
  354. If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one.
  355. .. rst-class:: classref-item-separator
  356. ----
  357. .. _class_RigidBody2D_property_sleeping:
  358. .. rst-class:: classref-property
  359. :ref:`bool<class_bool>` **sleeping** = ``false``
  360. .. rst-class:: classref-property-setget
  361. - void **set_sleeping** **(** :ref:`bool<class_bool>` value **)**
  362. - :ref:`bool<class_bool>` **is_sleeping** **(** **)**
  363. 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.
  364. .. rst-class:: classref-item-separator
  365. ----
  366. .. _class_RigidBody2D_property_weight:
  367. .. rst-class:: classref-property
  368. :ref:`float<class_float>` **weight** = ``9.8``
  369. .. rst-class:: classref-property-setget
  370. - void **set_weight** **(** :ref:`float<class_float>` value **)**
  371. - :ref:`float<class_float>` **get_weight** **(** **)**
  372. The body's weight based on its mass and the **Default Gravity** value in **Project > Project Settings > Physics > 2d**.
  373. .. rst-class:: classref-section-separator
  374. ----
  375. .. rst-class:: classref-descriptions-group
  376. Method Descriptions
  377. -------------------
  378. .. _class_RigidBody2D_method__integrate_forces:
  379. .. rst-class:: classref-method
  380. void **_integrate_forces** **(** :ref:`Physics2DDirectBodyState<class_Physics2DDirectBodyState>` state **)** |virtual|
  381. 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.
  382. .. rst-class:: classref-item-separator
  383. ----
  384. .. _class_RigidBody2D_method_add_central_force:
  385. .. rst-class:: classref-method
  386. void **add_central_force** **(** :ref:`Vector2<class_Vector2>` force **)**
  387. Adds a constant directional force without affecting rotation.
  388. .. rst-class:: classref-item-separator
  389. ----
  390. .. _class_RigidBody2D_method_add_force:
  391. .. rst-class:: classref-method
  392. void **add_force** **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` force **)**
  393. Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
  394. .. rst-class:: classref-item-separator
  395. ----
  396. .. _class_RigidBody2D_method_add_torque:
  397. .. rst-class:: classref-method
  398. void **add_torque** **(** :ref:`float<class_float>` torque **)**
  399. Adds a constant rotational force.
  400. .. rst-class:: classref-item-separator
  401. ----
  402. .. _class_RigidBody2D_method_apply_central_impulse:
  403. .. rst-class:: classref-method
  404. void **apply_central_impulse** **(** :ref:`Vector2<class_Vector2>` impulse **)**
  405. Applies a directional impulse without affecting rotation.
  406. .. rst-class:: classref-item-separator
  407. ----
  408. .. _class_RigidBody2D_method_apply_impulse:
  409. .. rst-class:: classref-method
  410. void **apply_impulse** **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` impulse **)**
  411. 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.
  412. .. rst-class:: classref-item-separator
  413. ----
  414. .. _class_RigidBody2D_method_apply_torque_impulse:
  415. .. rst-class:: classref-method
  416. void **apply_torque_impulse** **(** :ref:`float<class_float>` torque **)**
  417. Applies a rotational impulse to the body.
  418. .. rst-class:: classref-item-separator
  419. ----
  420. .. _class_RigidBody2D_method_get_colliding_bodies:
  421. .. rst-class:: classref-method
  422. :ref:`Array<class_Array>` **get_colliding_bodies** **(** **)** |const|
  423. 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.
  424. \ **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.
  425. .. rst-class:: classref-item-separator
  426. ----
  427. .. _class_RigidBody2D_method_set_axis_velocity:
  428. .. rst-class:: classref-method
  429. void **set_axis_velocity** **(** :ref:`Vector2<class_Vector2>` axis_velocity **)**
  430. 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.
  431. .. rst-class:: classref-item-separator
  432. ----
  433. .. _class_RigidBody2D_method_test_motion:
  434. .. rst-class:: classref-method
  435. :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 **)**
  436. 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).
  437. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  438. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  439. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  440. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`