class_rigidbody2d.rst 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_RigidBody2D:
  4. RigidBody2D
  5. ===========
  6. **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>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Rigid body 2D node.
  11. Member Functions
  12. ----------------
  13. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | void | :ref:`_integrate_forces<class_RigidBody2D__integrate_forces>` **(** :ref:`Physics2DDirectBodyState<class_physics2ddirectbodystate>` state **)** virtual |
  15. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`add_force<class_RigidBody2D_add_force>` **(** :ref:`Vector2<class_vector2>` offset, :ref:`Vector2<class_vector2>` force **)** |
  17. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | void | :ref:`apply_impulse<class_RigidBody2D_apply_impulse>` **(** :ref:`Vector2<class_vector2>` offset, :ref:`Vector2<class_vector2>` impulse **)** |
  19. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`float<class_float>` | :ref:`get_angular_damp<class_RigidBody2D_get_angular_damp>` **(** **)** const |
  21. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`float<class_float>` | :ref:`get_angular_velocity<class_RigidBody2D_get_angular_velocity>` **(** **)** const |
  23. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`Vector2<class_vector2>` | :ref:`get_applied_force<class_RigidBody2D_get_applied_force>` **(** **)** const |
  25. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`float<class_float>` | :ref:`get_applied_torque<class_RigidBody2D_get_applied_torque>` **(** **)** const |
  27. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`float<class_float>` | :ref:`get_bounce<class_RigidBody2D_get_bounce>` **(** **)** const |
  29. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Array<class_array>` | :ref:`get_colliding_bodies<class_RigidBody2D_get_colliding_bodies>` **(** **)** const |
  31. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`int<class_int>` | :ref:`get_continuous_collision_detection_mode<class_RigidBody2D_get_continuous_collision_detection_mode>` **(** **)** const |
  33. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`float<class_float>` | :ref:`get_friction<class_RigidBody2D_get_friction>` **(** **)** const |
  35. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`get_gravity_scale<class_RigidBody2D_get_gravity_scale>` **(** **)** const |
  37. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`float<class_float>` | :ref:`get_inertia<class_RigidBody2D_get_inertia>` **(** **)** const |
  39. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`float<class_float>` | :ref:`get_linear_damp<class_RigidBody2D_get_linear_damp>` **(** **)** const |
  41. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Vector2<class_vector2>` | :ref:`get_linear_velocity<class_RigidBody2D_get_linear_velocity>` **(** **)** const |
  43. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`float<class_float>` | :ref:`get_mass<class_RigidBody2D_get_mass>` **(** **)** const |
  45. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`get_max_contacts_reported<class_RigidBody2D_get_max_contacts_reported>` **(** **)** const |
  47. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`int<class_int>` | :ref:`get_mode<class_RigidBody2D_get_mode>` **(** **)** const |
  49. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`float<class_float>` | :ref:`get_weight<class_RigidBody2D_get_weight>` **(** **)** const |
  51. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`bool<class_bool>` | :ref:`is_able_to_sleep<class_RigidBody2D_is_able_to_sleep>` **(** **)** const |
  53. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`bool<class_bool>` | :ref:`is_contact_monitor_enabled<class_RigidBody2D_is_contact_monitor_enabled>` **(** **)** const |
  55. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`bool<class_bool>` | :ref:`is_sleeping<class_RigidBody2D_is_sleeping>` **(** **)** const |
  57. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`bool<class_bool>` | :ref:`is_using_custom_integrator<class_RigidBody2D_is_using_custom_integrator>` **(** **)** |
  59. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`set_angular_damp<class_RigidBody2D_set_angular_damp>` **(** :ref:`float<class_float>` angular_damp **)** |
  61. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`set_angular_velocity<class_RigidBody2D_set_angular_velocity>` **(** :ref:`float<class_float>` angular_velocity **)** |
  63. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`set_applied_force<class_RigidBody2D_set_applied_force>` **(** :ref:`Vector2<class_vector2>` force **)** |
  65. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`set_applied_torque<class_RigidBody2D_set_applied_torque>` **(** :ref:`float<class_float>` torque **)** |
  67. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`set_axis_velocity<class_RigidBody2D_set_axis_velocity>` **(** :ref:`Vector2<class_vector2>` axis_velocity **)** |
  69. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`set_bounce<class_RigidBody2D_set_bounce>` **(** :ref:`float<class_float>` bounce **)** |
  71. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`set_can_sleep<class_RigidBody2D_set_can_sleep>` **(** :ref:`bool<class_bool>` able_to_sleep **)** |
  73. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`set_contact_monitor<class_RigidBody2D_set_contact_monitor>` **(** :ref:`bool<class_bool>` enabled **)** |
  75. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`set_continuous_collision_detection_mode<class_RigidBody2D_set_continuous_collision_detection_mode>` **(** :ref:`int<class_int>` mode **)** |
  77. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`set_friction<class_RigidBody2D_set_friction>` **(** :ref:`float<class_float>` friction **)** |
  79. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`set_gravity_scale<class_RigidBody2D_set_gravity_scale>` **(** :ref:`float<class_float>` gravity_scale **)** |
  81. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`set_inertia<class_RigidBody2D_set_inertia>` **(** :ref:`float<class_float>` inertia **)** |
  83. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`set_linear_damp<class_RigidBody2D_set_linear_damp>` **(** :ref:`float<class_float>` linear_damp **)** |
  85. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | void | :ref:`set_linear_velocity<class_RigidBody2D_set_linear_velocity>` **(** :ref:`Vector2<class_vector2>` linear_velocity **)** |
  87. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | void | :ref:`set_mass<class_RigidBody2D_set_mass>` **(** :ref:`float<class_float>` mass **)** |
  89. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | void | :ref:`set_max_contacts_reported<class_RigidBody2D_set_max_contacts_reported>` **(** :ref:`int<class_int>` amount **)** |
  91. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | void | :ref:`set_mode<class_RigidBody2D_set_mode>` **(** :ref:`int<class_int>` mode **)** |
  93. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | void | :ref:`set_sleeping<class_RigidBody2D_set_sleeping>` **(** :ref:`bool<class_bool>` sleeping **)** |
  95. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | void | :ref:`set_use_custom_integrator<class_RigidBody2D_set_use_custom_integrator>` **(** :ref:`bool<class_bool>` enable **)** |
  97. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | void | :ref:`set_weight<class_RigidBody2D_set_weight>` **(** :ref:`float<class_float>` weight **)** |
  99. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`bool<class_bool>` | :ref:`test_motion<class_RigidBody2D_test_motion>` **(** :ref:`Vector2<class_vector2>` motion, :ref:`float<class_float>` margin=0.08, :ref:`Physics2DTestMotionResult<class_physics2dtestmotionresult>` result=NULL **)** |
  101. +--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. Signals
  103. -------
  104. - **body_enter** **(** :ref:`Object<class_object>` body **)**
  105. Emitted when a body enters into contact with this one. Contact monitor and contacts reported must be enabled for this to work.
  106. - **body_enter_shape** **(** :ref:`int<class_int>` body_id, :ref:`Object<class_object>` body, :ref:`int<class_int>` body_shape, :ref:`int<class_int>` local_shape **)**
  107. Emitted when a body enters into contact with this one. Contact monitor and contacts reported must be enabled for this to work.
  108. This signal not only receives the body that collided with this one, but also its :ref:`RID<class_rid>` (body_id), the shape index from the colliding body (body_shape), and the shape index from this body (local_shape) the other body collided with.
  109. - **body_exit** **(** :ref:`Object<class_object>` body **)**
  110. Emitted when a body exits contact with this one. Contact monitor and contacts reported must be enabled for this to work.
  111. - **body_exit_shape** **(** :ref:`int<class_int>` body_id, :ref:`Object<class_object>` body, :ref:`int<class_int>` body_shape, :ref:`int<class_int>` local_shape **)**
  112. Emitted when a body shape exits contact with this one. Contact monitor and contacts reported must be enabled for this to work.
  113. This signal not only receives the body that stopped colliding with this one, but also its :ref:`RID<class_rid>` (body_id), the shape index from the colliding body (body_shape), and the shape index from this body (local_shape) the other body stopped colliding with.
  114. - **sleeping_state_changed** **(** **)**
  115. Emitted when the body changes its sleeping state. Either by sleeping or waking up.
  116. Numeric Constants
  117. -----------------
  118. - **MODE_STATIC** = **1** --- Static mode. The body behaves like a :ref:`StaticBody2D<class_staticbody2d>`, and can only move by user code.
  119. - **MODE_KINEMATIC** = **3** --- Kinematic body. The body behaves like a :ref:`KinematicBody2D<class_kinematicbody2d>`, and can only move by user code.
  120. - **MODE_RIGID** = **0** --- Rigid body. This is the "natural" state of a rigid body. It is affected by forces, and can move, rotate, and be affected by user code.
  121. - **MODE_CHARACTER** = **2** --- Character body. This behaves like a rigid body, but can not rotate.
  122. - **CCD_MODE_DISABLED** = **0** --- Disables continuous collision detection. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
  123. - **CCD_MODE_CAST_RAY** = **1** --- Enables continuous collision detection by raycasting. It is faster than shapecasting, but less precise.
  124. - **CCD_MODE_CAST_SHAPE** = **2** --- Enables continuous collision detection by shapecasting. It is the slowest CCD method, and the most precise.
  125. Description
  126. -----------
  127. Rigid body 2D node. This node is used for placing rigid bodies in the scene. It can contain a number of shapes, and also shift state between regular Rigid body, Kinematic, Character or Static.
  128. Character mode forbids the node from being rotated. This node can have a custom force integrator function, for writing complex physics motion behavior per node.
  129. As a warning, don't change this node position every frame or very often. Sporadic changes work fine, but physics runs at a different granularity (fixed hz) than usual rendering (process callback) and maybe even in a separate thread, so changing this from a process loop will yield strange behavior.
  130. Member Function Description
  131. ---------------------------
  132. .. _class_RigidBody2D__integrate_forces:
  133. - void **_integrate_forces** **(** :ref:`Physics2DDirectBodyState<class_physics2ddirectbodystate>` state **)** virtual
  134. Called during physics processing, allowing you to read and safely modify the simulation state for the object. By default it works in addition to the usual physics behavior, but :ref:`set_use_custom_integrator<class_RigidBody2D_set_use_custom_integrator>` allows you to disable the default behavior and do fully custom force integration for a body.
  135. .. _class_RigidBody2D_add_force:
  136. - void **add_force** **(** :ref:`Vector2<class_vector2>` offset, :ref:`Vector2<class_vector2>` force **)**
  137. Add a positioned force to the applied force and torque. As with :ref:`apply_impulse<class_RigidBody2D_apply_impulse>`, both the force and the offset from the body origin are in global coordinates.
  138. .. _class_RigidBody2D_apply_impulse:
  139. - void **apply_impulse** **(** :ref:`Vector2<class_vector2>` offset, :ref:`Vector2<class_vector2>` impulse **)**
  140. Apply a positioned impulse (which will be affected by the body mass and shape). This is the equivalent of hitting a billiard ball with a cue: a force that is applied once, and only once. Both the impulse and the offset from the body origin are in global coordinates.
  141. .. _class_RigidBody2D_get_angular_damp:
  142. - :ref:`float<class_float>` **get_angular_damp** **(** **)** const
  143. Return the angular damp for this body.
  144. .. _class_RigidBody2D_get_angular_velocity:
  145. - :ref:`float<class_float>` **get_angular_velocity** **(** **)** const
  146. Return the body angular velocity. This changes by physics granularity. See :ref:`set_angular_velocity<class_RigidBody2D_set_angular_velocity>`.
  147. .. _class_RigidBody2D_get_applied_force:
  148. - :ref:`Vector2<class_vector2>` **get_applied_force** **(** **)** const
  149. Return the applied force vector.
  150. .. _class_RigidBody2D_get_applied_torque:
  151. - :ref:`float<class_float>` **get_applied_torque** **(** **)** const
  152. Return the torque which is being applied to this body.
  153. .. _class_RigidBody2D_get_bounce:
  154. - :ref:`float<class_float>` **get_bounce** **(** **)** const
  155. Return the body bounciness.
  156. .. _class_RigidBody2D_get_colliding_bodies:
  157. - :ref:`Array<class_array>` **get_colliding_bodies** **(** **)** const
  158. Return a list of the bodies colliding with this one. By default, number of max contacts reported is at 0 , see :ref:`set_max_contacts_reported<class_RigidBody2D_set_max_contacts_reported>` to increase it. You must also enable contact monitor, see :ref:`set_contact_monitor<class_RigidBody2D_set_contact_monitor>`
  159. .. _class_RigidBody2D_get_continuous_collision_detection_mode:
  160. - :ref:`int<class_int>` **get_continuous_collision_detection_mode** **(** **)** const
  161. Return whether this body is using continuous collision detection.
  162. .. _class_RigidBody2D_get_friction:
  163. - :ref:`float<class_float>` **get_friction** **(** **)** const
  164. Return the body friction.
  165. .. _class_RigidBody2D_get_gravity_scale:
  166. - :ref:`float<class_float>` **get_gravity_scale** **(** **)** const
  167. Return the gravity factor.
  168. .. _class_RigidBody2D_get_inertia:
  169. - :ref:`float<class_float>` **get_inertia** **(** **)** const
  170. Return the body's moment of inertia. This is usually automatically computed from the mass and the shapes. Note that this doesn't seem to work in a ``_ready`` function: it apparently has not been auto-computed yet.
  171. .. _class_RigidBody2D_get_linear_damp:
  172. - :ref:`float<class_float>` **get_linear_damp** **(** **)** const
  173. Return the linear damp for this body.
  174. .. _class_RigidBody2D_get_linear_velocity:
  175. - :ref:`Vector2<class_vector2>` **get_linear_velocity** **(** **)** const
  176. Return the body linear velocity. This changes by physics granularity. See :ref:`set_linear_velocity<class_RigidBody2D_set_linear_velocity>`.
  177. .. _class_RigidBody2D_get_mass:
  178. - :ref:`float<class_float>` **get_mass** **(** **)** const
  179. Return the body mass.
  180. .. _class_RigidBody2D_get_max_contacts_reported:
  181. - :ref:`int<class_int>` **get_max_contacts_reported** **(** **)** const
  182. Return the maximum contacts that can be reported. See :ref:`set_max_contacts_reported<class_RigidBody2D_set_max_contacts_reported>`.
  183. .. _class_RigidBody2D_get_mode:
  184. - :ref:`int<class_int>` **get_mode** **(** **)** const
  185. Return the current body mode, see :ref:`set_mode<class_RigidBody2D_set_mode>`.
  186. .. _class_RigidBody2D_get_weight:
  187. - :ref:`float<class_float>` **get_weight** **(** **)** const
  188. Return the body weight given standard earth-weight (gravity 9.8).
  189. .. _class_RigidBody2D_is_able_to_sleep:
  190. - :ref:`bool<class_bool>` **is_able_to_sleep** **(** **)** const
  191. Return true if the body has the ability to fall asleep when not moving. See :ref:`set_can_sleep<class_RigidBody2D_set_can_sleep>`.
  192. .. _class_RigidBody2D_is_contact_monitor_enabled:
  193. - :ref:`bool<class_bool>` **is_contact_monitor_enabled** **(** **)** const
  194. Return whether contact monitoring is enabled.
  195. .. _class_RigidBody2D_is_sleeping:
  196. - :ref:`bool<class_bool>` **is_sleeping** **(** **)** const
  197. Return whether the body is sleeping.
  198. .. _class_RigidBody2D_is_using_custom_integrator:
  199. - :ref:`bool<class_bool>` **is_using_custom_integrator** **(** **)**
  200. Return true if the body is not doing any built-in force integration.
  201. .. _class_RigidBody2D_set_angular_damp:
  202. - void **set_angular_damp** **(** :ref:`float<class_float>` angular_damp **)**
  203. Set the angular damp for this body. If this value is different from -1, any angular damp derived from the world or areas will be overridden.
  204. .. _class_RigidBody2D_set_angular_velocity:
  205. - void **set_angular_velocity** **(** :ref:`float<class_float>` angular_velocity **)**
  206. Set the body angular velocity. Can be used sporadically, but **DON'T SET THIS IN EVERY FRAME**, because physics may be running in another thread and definitely runs at a different granularity. Use :ref:`_integrate_forces<class_RigidBody2D__integrate_forces>` as your process loop if you want to have precise control of the body state.
  207. .. _class_RigidBody2D_set_applied_force:
  208. - void **set_applied_force** **(** :ref:`Vector2<class_vector2>` force **)**
  209. Set the applied force vector. This is the equivalent of pushing a box over the ground: the force applied is applied constantly.
  210. .. _class_RigidBody2D_set_applied_torque:
  211. - void **set_applied_torque** **(** :ref:`float<class_float>` torque **)**
  212. Set a constant torque which will be applied to this body.
  213. .. _class_RigidBody2D_set_axis_velocity:
  214. - void **set_axis_velocity** **(** :ref:`Vector2<class_vector2>` axis_velocity **)**
  215. Set an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
  216. .. _class_RigidBody2D_set_bounce:
  217. - void **set_bounce** **(** :ref:`float<class_float>` bounce **)**
  218. Set the body bounciness, from 0 (no bounce) to 1 (full bounce).
  219. .. _class_RigidBody2D_set_can_sleep:
  220. - void **set_can_sleep** **(** :ref:`bool<class_bool>` able_to_sleep **)**
  221. Set the body ability to fall asleep when not moving. This saves an enormous amount of processor time when there are plenty of rigid bodies (non static) in a scene.
  222. Sleeping bodies are not affected by forces until a collision or an :ref:`apply_impulse<class_RigidBody2D_apply_impulse>` / :ref:`set_applied_force<class_RigidBody2D_set_applied_force>` wakes them up. Until then, they behave like a static body.
  223. .. _class_RigidBody2D_set_contact_monitor:
  224. - void **set_contact_monitor** **(** :ref:`bool<class_bool>` enabled **)**
  225. Enable contact monitoring. This allows the body to emit signals when it collides with another.
  226. .. _class_RigidBody2D_set_continuous_collision_detection_mode:
  227. - void **set_continuous_collision_detection_mode** **(** :ref:`int<class_int>` mode **)**
  228. Set the continuous collision detection mode from the enum CCD_MODE\_\*.
  229. Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided. The first is more precise, and misses less impacts by small, fast-moving objects. The second is faster to compute, but can miss small, fast-moving objects.
  230. .. _class_RigidBody2D_set_friction:
  231. - void **set_friction** **(** :ref:`float<class_float>` friction **)**
  232. Set the body friction, from 0 (frictionless) to 1 (full friction).
  233. .. _class_RigidBody2D_set_gravity_scale:
  234. - void **set_gravity_scale** **(** :ref:`float<class_float>` gravity_scale **)**
  235. Set the gravity factor. This factor multiplies gravity intensity just for this body.
  236. .. _class_RigidBody2D_set_inertia:
  237. - void **set_inertia** **(** :ref:`float<class_float>` inertia **)**
  238. Set 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.
  239. .. _class_RigidBody2D_set_linear_damp:
  240. - void **set_linear_damp** **(** :ref:`float<class_float>` linear_damp **)**
  241. Set the linear damp for this body. If this value is different from -1, any linear damp derived from the world or areas will be overridden.
  242. .. _class_RigidBody2D_set_linear_velocity:
  243. - void **set_linear_velocity** **(** :ref:`Vector2<class_vector2>` linear_velocity **)**
  244. Set the body linear velocity. Can be used sporadically, but **DON'T SET THIS IN EVERY FRAME**, because physics may be running in another thread and definitely runs at a different granularity. Use :ref:`_integrate_forces<class_RigidBody2D__integrate_forces>` as your process loop if you want to have precise control of the body state.
  245. .. _class_RigidBody2D_set_mass:
  246. - void **set_mass** **(** :ref:`float<class_float>` mass **)**
  247. Set the body mass.
  248. .. _class_RigidBody2D_set_max_contacts_reported:
  249. - void **set_max_contacts_reported** **(** :ref:`int<class_int>` amount **)**
  250. Set the maximum contacts to report. Bodies can keep a log of the contacts with other bodies, this is enabled by setting the maximum amount of contacts reported to a number greater than 0.
  251. .. _class_RigidBody2D_set_mode:
  252. - void **set_mode** **(** :ref:`int<class_int>` mode **)**
  253. Set the body mode, from the MODE\_\* enum. This allows to change to a static body or a character body.
  254. .. _class_RigidBody2D_set_sleeping:
  255. - void **set_sleeping** **(** :ref:`bool<class_bool>` sleeping **)**
  256. Set whether a body is sleeping or not. Sleeping bodies are not affected by forces until a collision or an :ref:`apply_impulse<class_RigidBody2D_apply_impulse>` / :ref:`set_applied_force<class_RigidBody2D_set_applied_force>` wakes them up. Until then, they behave like a static body.
  257. .. _class_RigidBody2D_set_use_custom_integrator:
  258. - void **set_use_custom_integrator** **(** :ref:`bool<class_bool>` enable **)**
  259. Pass true to disable the internal force integration (like gravity or air friction) for this body. Other than collision response, the body will only move as determined by the :ref:`_integrate_forces<class_RigidBody2D__integrate_forces>` function, if defined.
  260. .. _class_RigidBody2D_set_weight:
  261. - void **set_weight** **(** :ref:`float<class_float>` weight **)**
  262. Set the body weight given standard earth-weight (gravity 9.8). Not really useful for 2D since most measures for this node are in pixels.
  263. .. _class_RigidBody2D_test_motion:
  264. - :ref:`bool<class_bool>` **test_motion** **(** :ref:`Vector2<class_vector2>` motion, :ref:`float<class_float>` margin=0.08, :ref:`Physics2DTestMotionResult<class_physics2dtestmotionresult>` result=NULL **)**
  265. Return whether the body would collide, if it tried to move in the given vector. This method allows two extra parameters: A margin, which increases slightly the size of the shapes involved in the collision detection, and an object of type :ref:`Physics2DTestMotionResult<class_physics2dtestmotionresult>`, which will store additional information about the collision (should there be one).