class_rigidbody2d.rst 37 KB

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