class_rigidbody2d.rst 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.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. **Category:** Core
  10. Brief Description
  11. -----------------
  12. A body that is controlled by the 2D physics engine.
  13. Properties
  14. ----------
  15. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  16. | :ref:`float<class_float>` | :ref:`angular_damp<class_RigidBody2D_property_angular_damp>` |
  17. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  18. | :ref:`float<class_float>` | :ref:`angular_velocity<class_RigidBody2D_property_angular_velocity>` |
  19. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  20. | :ref:`Vector2<class_Vector2>` | :ref:`applied_force<class_RigidBody2D_property_applied_force>` |
  21. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  22. | :ref:`float<class_float>` | :ref:`applied_torque<class_RigidBody2D_property_applied_torque>` |
  23. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  24. | :ref:`float<class_float>` | :ref:`bounce<class_RigidBody2D_property_bounce>` |
  25. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | :ref:`can_sleep<class_RigidBody2D_property_can_sleep>` |
  27. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` |
  29. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  30. | :ref:`int<class_int>` | :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>` |
  31. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  32. | :ref:`CCDMode<enum_RigidBody2D_CCDMode>` | :ref:`continuous_cd<class_RigidBody2D_property_continuous_cd>` |
  33. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  34. | :ref:`bool<class_bool>` | :ref:`custom_integrator<class_RigidBody2D_property_custom_integrator>` |
  35. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`friction<class_RigidBody2D_property_friction>` |
  37. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  38. | :ref:`float<class_float>` | :ref:`gravity_scale<class_RigidBody2D_property_gravity_scale>` |
  39. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  40. | :ref:`float<class_float>` | :ref:`inertia<class_RigidBody2D_property_inertia>` |
  41. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  42. | :ref:`float<class_float>` | :ref:`linear_damp<class_RigidBody2D_property_linear_damp>` |
  43. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  44. | :ref:`Vector2<class_Vector2>` | :ref:`linear_velocity<class_RigidBody2D_property_linear_velocity>` |
  45. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  46. | :ref:`float<class_float>` | :ref:`mass<class_RigidBody2D_property_mass>` |
  47. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  48. | :ref:`Mode<enum_RigidBody2D_Mode>` | :ref:`mode<class_RigidBody2D_property_mode>` |
  49. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  50. | :ref:`PhysicsMaterial<class_PhysicsMaterial>` | :ref:`physics_material_override<class_RigidBody2D_property_physics_material_override>` |
  51. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  52. | :ref:`bool<class_bool>` | :ref:`sleeping<class_RigidBody2D_property_sleeping>` |
  53. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  54. | :ref:`float<class_float>` | :ref:`weight<class_RigidBody2D_property_weight>` |
  55. +-----------------------------------------------+----------------------------------------------------------------------------------------+
  56. Methods
  57. -------
  58. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`_integrate_forces<class_RigidBody2D_method__integrate_forces>` **(** :ref:`Physics2DDirectBodyState<class_Physics2DDirectBodyState>` state **)** virtual |
  60. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`add_central_force<class_RigidBody2D_method_add_central_force>` **(** :ref:`Vector2<class_Vector2>` force **)** |
  62. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`add_force<class_RigidBody2D_method_add_force>` **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` force **)** |
  64. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`add_torque<class_RigidBody2D_method_add_torque>` **(** :ref:`float<class_float>` torque **)** |
  66. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`apply_central_impulse<class_RigidBody2D_method_apply_central_impulse>` **(** :ref:`Vector2<class_Vector2>` impulse **)** |
  68. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`apply_impulse<class_RigidBody2D_method_apply_impulse>` **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` impulse **)** |
  70. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`apply_torque_impulse<class_RigidBody2D_method_apply_torque_impulse>` **(** :ref:`float<class_float>` torque **)** |
  72. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Array<class_Array>` | :ref:`get_colliding_bodies<class_RigidBody2D_method_get_colliding_bodies>` **(** **)** const |
  74. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`set_axis_velocity<class_RigidBody2D_method_set_axis_velocity>` **(** :ref:`Vector2<class_Vector2>` axis_velocity **)** |
  76. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :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 **)** |
  78. +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. Signals
  80. -------
  81. .. _class_RigidBody2D_signal_body_entered:
  82. - **body_entered** **(** :ref:`Node<class_Node>` body **)**
  83. Emitted when a body enters into contact with this one. :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` must be ``true`` and :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>` greater than ``0``.
  84. ----
  85. .. _class_RigidBody2D_signal_body_exited:
  86. - **body_exited** **(** :ref:`Node<class_Node>` body **)**
  87. Emitted when a body exits contact with this one. :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` must be ``true`` and :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>` greater than ``0``.
  88. ----
  89. .. _class_RigidBody2D_signal_body_shape_entered:
  90. - **body_shape_entered** **(** :ref:`int<class_int>` body_id, :ref:`Node<class_Node>` body, :ref:`int<class_int>` body_shape, :ref:`int<class_int>` local_shape **)**
  91. Emitted when a body enters into contact with this one. Reports colliding shape information. See :ref:`CollisionObject2D<class_CollisionObject2D>` for shape index information. :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` must be ``true`` and :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>` greater than ``0``.
  92. ----
  93. .. _class_RigidBody2D_signal_body_shape_exited:
  94. - **body_shape_exited** **(** :ref:`int<class_int>` body_id, :ref:`Node<class_Node>` body, :ref:`int<class_int>` body_shape, :ref:`int<class_int>` local_shape **)**
  95. Emitted when a body shape exits contact with this one. Reports colliding shape information. See :ref:`CollisionObject2D<class_CollisionObject2D>` for shape index information. :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` must be ``true`` and :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>` greater than ``0``.
  96. ----
  97. .. _class_RigidBody2D_signal_sleeping_state_changed:
  98. - **sleeping_state_changed** **(** **)**
  99. Emitted when :ref:`sleeping<class_RigidBody2D_property_sleeping>` changes.
  100. Enumerations
  101. ------------
  102. .. _enum_RigidBody2D_Mode:
  103. .. _class_RigidBody2D_constant_MODE_RIGID:
  104. .. _class_RigidBody2D_constant_MODE_STATIC:
  105. .. _class_RigidBody2D_constant_MODE_CHARACTER:
  106. .. _class_RigidBody2D_constant_MODE_KINEMATIC:
  107. enum **Mode**:
  108. - **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.
  109. - **MODE_STATIC** = **1** --- Static mode. The body behaves like a :ref:`StaticBody2D<class_StaticBody2D>` and does not move.
  110. - **MODE_CHARACTER** = **2** --- Character mode. Similar to :ref:`MODE_RIGID<class_RigidBody2D_constant_MODE_RIGID>`, but the body can not rotate.
  111. - **MODE_KINEMATIC** = **3** --- Kinematic mode. The body behaves like a :ref:`KinematicBody2D<class_KinematicBody2D>`, and must be moved by code.
  112. ----
  113. .. _enum_RigidBody2D_CCDMode:
  114. .. _class_RigidBody2D_constant_CCD_MODE_DISABLED:
  115. .. _class_RigidBody2D_constant_CCD_MODE_CAST_RAY:
  116. .. _class_RigidBody2D_constant_CCD_MODE_CAST_SHAPE:
  117. enum **CCDMode**:
  118. - **CCD_MODE_DISABLED** = **0** --- Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
  119. - **CCD_MODE_CAST_RAY** = **1** --- Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise.
  120. - **CCD_MODE_CAST_SHAPE** = **2** --- Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise.
  121. Description
  122. -----------
  123. 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.
  124. A RigidBody2D has 4 behavior :ref:`mode<class_RigidBody2D_property_mode>`\ s: Rigid, Static, Character, and Kinematic.
  125. **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.
  126. 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.
  127. 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>`.
  128. Property Descriptions
  129. ---------------------
  130. .. _class_RigidBody2D_property_angular_damp:
  131. - :ref:`float<class_float>` **angular_damp**
  132. +----------+-------------------------+
  133. | *Setter* | set_angular_damp(value) |
  134. +----------+-------------------------+
  135. | *Getter* | get_angular_damp() |
  136. +----------+-------------------------+
  137. Damps the body's :ref:`angular_velocity<class_RigidBody2D_property_angular_velocity>`. If ``-1`` the body will use the "Default Angular Damp" in "Project > Project Settings > Physics > 2d". Default value: ``-1``.
  138. ----
  139. .. _class_RigidBody2D_property_angular_velocity:
  140. - :ref:`float<class_float>` **angular_velocity**
  141. +----------+-----------------------------+
  142. | *Setter* | set_angular_velocity(value) |
  143. +----------+-----------------------------+
  144. | *Getter* | get_angular_velocity() |
  145. +----------+-----------------------------+
  146. The body's rotational velocity.
  147. ----
  148. .. _class_RigidBody2D_property_applied_force:
  149. - :ref:`Vector2<class_Vector2>` **applied_force**
  150. +----------+--------------------------+
  151. | *Setter* | set_applied_force(value) |
  152. +----------+--------------------------+
  153. | *Getter* | get_applied_force() |
  154. +----------+--------------------------+
  155. The body's total applied force.
  156. ----
  157. .. _class_RigidBody2D_property_applied_torque:
  158. - :ref:`float<class_float>` **applied_torque**
  159. +----------+---------------------------+
  160. | *Setter* | set_applied_torque(value) |
  161. +----------+---------------------------+
  162. | *Getter* | get_applied_torque() |
  163. +----------+---------------------------+
  164. The body's total applied torque.
  165. ----
  166. .. _class_RigidBody2D_property_bounce:
  167. - :ref:`float<class_float>` **bounce**
  168. +----------+-------------------+
  169. | *Setter* | set_bounce(value) |
  170. +----------+-------------------+
  171. | *Getter* | get_bounce() |
  172. +----------+-------------------+
  173. The body's bounciness. Default value: ``0``.
  174. ----
  175. .. _class_RigidBody2D_property_can_sleep:
  176. - :ref:`bool<class_bool>` **can_sleep**
  177. +----------+----------------------+
  178. | *Setter* | set_can_sleep(value) |
  179. +----------+----------------------+
  180. | *Getter* | is_able_to_sleep() |
  181. +----------+----------------------+
  182. If ``true``, the body will not calculate forces and will act as a static body if there is no movement. The body will wake up when other forces are applied via collisions or by using :ref:`apply_impulse<class_RigidBody2D_method_apply_impulse>` or :ref:`add_force<class_RigidBody2D_method_add_force>`. Default value: ``true``.
  183. ----
  184. .. _class_RigidBody2D_property_contact_monitor:
  185. - :ref:`bool<class_bool>` **contact_monitor**
  186. +----------+------------------------------+
  187. | *Setter* | set_contact_monitor(value) |
  188. +----------+------------------------------+
  189. | *Getter* | is_contact_monitor_enabled() |
  190. +----------+------------------------------+
  191. If ``true``, the body will emit signals when it collides with another RigidBody2D. See also :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>`. Default value: ``false``.
  192. ----
  193. .. _class_RigidBody2D_property_contacts_reported:
  194. - :ref:`int<class_int>` **contacts_reported**
  195. +----------+----------------------------------+
  196. | *Setter* | set_max_contacts_reported(value) |
  197. +----------+----------------------------------+
  198. | *Getter* | get_max_contacts_reported() |
  199. +----------+----------------------------------+
  200. The maximum number of contacts to report. Default value: ``0``.
  201. ----
  202. .. _class_RigidBody2D_property_continuous_cd:
  203. - :ref:`CCDMode<enum_RigidBody2D_CCDMode>` **continuous_cd**
  204. +----------+------------------------------------------------+
  205. | *Setter* | set_continuous_collision_detection_mode(value) |
  206. +----------+------------------------------------------------+
  207. | *Getter* | get_continuous_collision_detection_mode() |
  208. +----------+------------------------------------------------+
  209. Continuous collision detection mode. Default value: :ref:`CCD_MODE_DISABLED<class_RigidBody2D_constant_CCD_MODE_DISABLED>`.
  210. 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.
  211. ----
  212. .. _class_RigidBody2D_property_custom_integrator:
  213. - :ref:`bool<class_bool>` **custom_integrator**
  214. +----------+----------------------------------+
  215. | *Setter* | set_use_custom_integrator(value) |
  216. +----------+----------------------------------+
  217. | *Getter* | is_using_custom_integrator() |
  218. +----------+----------------------------------+
  219. 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.
  220. ----
  221. .. _class_RigidBody2D_property_friction:
  222. - :ref:`float<class_float>` **friction**
  223. +----------+---------------------+
  224. | *Setter* | set_friction(value) |
  225. +----------+---------------------+
  226. | *Getter* | get_friction() |
  227. +----------+---------------------+
  228. The body's friction. Values range from ``0`` (frictionless) to ``1`` (maximum friction). Default value: ``1``.
  229. ----
  230. .. _class_RigidBody2D_property_gravity_scale:
  231. - :ref:`float<class_float>` **gravity_scale**
  232. +----------+--------------------------+
  233. | *Setter* | set_gravity_scale(value) |
  234. +----------+--------------------------+
  235. | *Getter* | get_gravity_scale() |
  236. +----------+--------------------------+
  237. 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. Default value: ``1``.
  238. ----
  239. .. _class_RigidBody2D_property_inertia:
  240. - :ref:`float<class_float>` **inertia**
  241. +----------+--------------------+
  242. | *Setter* | set_inertia(value) |
  243. +----------+--------------------+
  244. | *Getter* | get_inertia() |
  245. +----------+--------------------+
  246. 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 (or negative) inertia to return to automatically computing it.
  247. ----
  248. .. _class_RigidBody2D_property_linear_damp:
  249. - :ref:`float<class_float>` **linear_damp**
  250. +----------+------------------------+
  251. | *Setter* | set_linear_damp(value) |
  252. +----------+------------------------+
  253. | *Getter* | get_linear_damp() |
  254. +----------+------------------------+
  255. 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". Default value: ``-1``.
  256. ----
  257. .. _class_RigidBody2D_property_linear_velocity:
  258. - :ref:`Vector2<class_Vector2>` **linear_velocity**
  259. +----------+----------------------------+
  260. | *Setter* | set_linear_velocity(value) |
  261. +----------+----------------------------+
  262. | *Getter* | get_linear_velocity() |
  263. +----------+----------------------------+
  264. The body's linear velocity.
  265. ----
  266. .. _class_RigidBody2D_property_mass:
  267. - :ref:`float<class_float>` **mass**
  268. +----------+-----------------+
  269. | *Setter* | set_mass(value) |
  270. +----------+-----------------+
  271. | *Getter* | get_mass() |
  272. +----------+-----------------+
  273. The body's mass. Default value: ``1``.
  274. ----
  275. .. _class_RigidBody2D_property_mode:
  276. - :ref:`Mode<enum_RigidBody2D_Mode>` **mode**
  277. +----------+-----------------+
  278. | *Setter* | set_mode(value) |
  279. +----------+-----------------+
  280. | *Getter* | get_mode() |
  281. +----------+-----------------+
  282. The body's mode. See ``MODE_*`` constants. Default value: :ref:`MODE_RIGID<class_RigidBody2D_constant_MODE_RIGID>`.
  283. ----
  284. .. _class_RigidBody2D_property_physics_material_override:
  285. - :ref:`PhysicsMaterial<class_PhysicsMaterial>` **physics_material_override**
  286. +----------+--------------------------------------+
  287. | *Setter* | set_physics_material_override(value) |
  288. +----------+--------------------------------------+
  289. | *Getter* | get_physics_material_override() |
  290. +----------+--------------------------------------+
  291. ----
  292. .. _class_RigidBody2D_property_sleeping:
  293. - :ref:`bool<class_bool>` **sleeping**
  294. +----------+---------------------+
  295. | *Setter* | set_sleeping(value) |
  296. +----------+---------------------+
  297. | *Getter* | is_sleeping() |
  298. +----------+---------------------+
  299. If ``true``, the body is sleeping and will not calculate forces until woken up by a collision or by using :ref:`apply_impulse<class_RigidBody2D_method_apply_impulse>` or :ref:`add_force<class_RigidBody2D_method_add_force>`.
  300. ----
  301. .. _class_RigidBody2D_property_weight:
  302. - :ref:`float<class_float>` **weight**
  303. +----------+-------------------+
  304. | *Setter* | set_weight(value) |
  305. +----------+-------------------+
  306. | *Getter* | get_weight() |
  307. +----------+-------------------+
  308. The body's weight based on its mass and the "Default Gravity" value in "Project > Project Settings > Physics > 2d".
  309. Method Descriptions
  310. -------------------
  311. .. _class_RigidBody2D_method__integrate_forces:
  312. - void **_integrate_forces** **(** :ref:`Physics2DDirectBodyState<class_Physics2DDirectBodyState>` state **)** virtual
  313. 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.
  314. ----
  315. .. _class_RigidBody2D_method_add_central_force:
  316. - void **add_central_force** **(** :ref:`Vector2<class_Vector2>` force **)**
  317. Adds a constant directional force without affecting rotation.
  318. ----
  319. .. _class_RigidBody2D_method_add_force:
  320. - void **add_force** **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` force **)**
  321. Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
  322. ----
  323. .. _class_RigidBody2D_method_add_torque:
  324. - void **add_torque** **(** :ref:`float<class_float>` torque **)**
  325. Adds a constant rotational force.
  326. ----
  327. .. _class_RigidBody2D_method_apply_central_impulse:
  328. - void **apply_central_impulse** **(** :ref:`Vector2<class_Vector2>` impulse **)**
  329. Applies a directional impulse without affecting rotation.
  330. ----
  331. .. _class_RigidBody2D_method_apply_impulse:
  332. - void **apply_impulse** **(** :ref:`Vector2<class_Vector2>` offset, :ref:`Vector2<class_Vector2>` impulse **)**
  333. 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.
  334. ----
  335. .. _class_RigidBody2D_method_apply_torque_impulse:
  336. - void **apply_torque_impulse** **(** :ref:`float<class_float>` torque **)**
  337. Applies a rotational impulse to the body.
  338. ----
  339. .. _class_RigidBody2D_method_get_colliding_bodies:
  340. - :ref:`Array<class_Array>` **get_colliding_bodies** **(** **)** const
  341. Returns a list of the bodies colliding with this one. Use :ref:`contacts_reported<class_RigidBody2D_property_contacts_reported>` to set the maximum number reported. You must also set :ref:`contact_monitor<class_RigidBody2D_property_contact_monitor>` to ``true``. Note that 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.
  342. ----
  343. .. _class_RigidBody2D_method_set_axis_velocity:
  344. - void **set_axis_velocity** **(** :ref:`Vector2<class_Vector2>` axis_velocity **)**
  345. 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.
  346. ----
  347. .. _class_RigidBody2D_method_test_motion:
  348. - :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 **)**
  349. 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).