class_rigidbody.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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_RigidBody:
  4. RigidBody
  5. =========
  6. **Inherits:** :ref:`PhysicsBody<class_physicsbody>` **<** :ref:`CollisionObject<class_collisionobject>` **<** :ref:`Spatial<class_spatial>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Rigid body node.
  11. Member Functions
  12. ----------------
  13. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | void | :ref:`_integrate_forces<class_RigidBody__integrate_forces>` **(** :ref:`PhysicsDirectBodyState<class_physicsdirectbodystate>` state **)** virtual |
  15. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`apply_impulse<class_RigidBody_apply_impulse>` **(** :ref:`Vector3<class_vector3>` pos, :ref:`Vector3<class_vector3>` impulse **)** |
  17. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`float<class_float>` | :ref:`get_angular_damp<class_RigidBody_get_angular_damp>` **(** **)** const |
  19. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`Vector3<class_vector3>` | :ref:`get_angular_velocity<class_RigidBody_get_angular_velocity>` **(** **)** const |
  21. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`int<class_int>` | :ref:`get_axis_lock<class_RigidBody_get_axis_lock>` **(** **)** const |
  23. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`float<class_float>` | :ref:`get_bounce<class_RigidBody_get_bounce>` **(** **)** const |
  25. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`Array<class_array>` | :ref:`get_colliding_bodies<class_RigidBody_get_colliding_bodies>` **(** **)** const |
  27. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`float<class_float>` | :ref:`get_friction<class_RigidBody_get_friction>` **(** **)** const |
  29. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`float<class_float>` | :ref:`get_gravity_scale<class_RigidBody_get_gravity_scale>` **(** **)** const |
  31. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`float<class_float>` | :ref:`get_linear_damp<class_RigidBody_get_linear_damp>` **(** **)** const |
  33. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`Vector3<class_vector3>` | :ref:`get_linear_velocity<class_RigidBody_get_linear_velocity>` **(** **)** const |
  35. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`get_mass<class_RigidBody_get_mass>` **(** **)** const |
  37. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`int<class_int>` | :ref:`get_max_contacts_reported<class_RigidBody_get_max_contacts_reported>` **(** **)** const |
  39. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`get_mode<class_RigidBody_get_mode>` **(** **)** const |
  41. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`float<class_float>` | :ref:`get_weight<class_RigidBody_get_weight>` **(** **)** const |
  43. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`is_able_to_sleep<class_RigidBody_is_able_to_sleep>` **(** **)** const |
  45. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`bool<class_bool>` | :ref:`is_contact_monitor_enabled<class_RigidBody_is_contact_monitor_enabled>` **(** **)** const |
  47. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`bool<class_bool>` | :ref:`is_sleeping<class_RigidBody_is_sleeping>` **(** **)** const |
  49. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`bool<class_bool>` | :ref:`is_using_continuous_collision_detection<class_RigidBody_is_using_continuous_collision_detection>` **(** **)** const |
  51. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`bool<class_bool>` | :ref:`is_using_custom_integrator<class_RigidBody_is_using_custom_integrator>` **(** **)** |
  53. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`set_angular_damp<class_RigidBody_set_angular_damp>` **(** :ref:`float<class_float>` angular_damp **)** |
  55. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`set_angular_velocity<class_RigidBody_set_angular_velocity>` **(** :ref:`Vector3<class_vector3>` angular_velocity **)** |
  57. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`set_axis_lock<class_RigidBody_set_axis_lock>` **(** :ref:`int<class_int>` axis_lock **)** |
  59. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`set_axis_velocity<class_RigidBody_set_axis_velocity>` **(** :ref:`Vector3<class_vector3>` axis_velocity **)** |
  61. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`set_bounce<class_RigidBody_set_bounce>` **(** :ref:`float<class_float>` bounce **)** |
  63. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`set_can_sleep<class_RigidBody_set_can_sleep>` **(** :ref:`bool<class_bool>` able_to_sleep **)** |
  65. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`set_contact_monitor<class_RigidBody_set_contact_monitor>` **(** :ref:`bool<class_bool>` enabled **)** |
  67. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`set_friction<class_RigidBody_set_friction>` **(** :ref:`float<class_float>` friction **)** |
  69. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`set_gravity_scale<class_RigidBody_set_gravity_scale>` **(** :ref:`float<class_float>` gravity_scale **)** |
  71. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`set_linear_damp<class_RigidBody_set_linear_damp>` **(** :ref:`float<class_float>` linear_damp **)** |
  73. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`set_linear_velocity<class_RigidBody_set_linear_velocity>` **(** :ref:`Vector3<class_vector3>` linear_velocity **)** |
  75. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`set_mass<class_RigidBody_set_mass>` **(** :ref:`float<class_float>` mass **)** |
  77. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | void | :ref:`set_max_contacts_reported<class_RigidBody_set_max_contacts_reported>` **(** :ref:`int<class_int>` amount **)** |
  79. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`set_mode<class_RigidBody_set_mode>` **(** :ref:`int<class_int>` mode **)** |
  81. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`set_sleeping<class_RigidBody_set_sleeping>` **(** :ref:`bool<class_bool>` sleeping **)** |
  83. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | void | :ref:`set_use_continuous_collision_detection<class_RigidBody_set_use_continuous_collision_detection>` **(** :ref:`bool<class_bool>` enable **)** |
  85. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | void | :ref:`set_use_custom_integrator<class_RigidBody_set_use_custom_integrator>` **(** :ref:`bool<class_bool>` enable **)** |
  87. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | void | :ref:`set_weight<class_RigidBody_set_weight>` **(** :ref:`float<class_float>` weight **)** |
  89. +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  90. Signals
  91. -------
  92. - **body_enter** **(** :ref:`Object<class_object>` body **)**
  93. Emitted when a body enters into contact with this one. Contact monitor and contacts reported must be enabled for this to work.
  94. - **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 **)**
  95. Emitted when a body enters into contact with this one. Contact monitor and contacts reported must be enabled for this to work.
  96. 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.
  97. - **body_exit** **(** :ref:`Object<class_object>` body **)**
  98. Emitted when a body shape exits contact with this one. Contact monitor and contacts reported must be enabled for this to work.
  99. - **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 **)**
  100. Emitted when a body shape exits contact with this one. Contact monitor and contacts reported must be enabled for this to work.
  101. 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.
  102. - **sleeping_state_changed** **(** **)**
  103. Emitted when the body changes its sleeping state. Either by sleeping or waking up.
  104. Numeric Constants
  105. -----------------
  106. - **MODE_STATIC** = **1** --- Static mode. The body behaves like a :ref:`StaticBody<class_staticbody>`, and can only move by user code.
  107. - **MODE_KINEMATIC** = **3** --- Kinematic body. The body behaves like a :ref:`KinematicBody<class_kinematicbody>`, and can only move by user code.
  108. - **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.
  109. - **MODE_CHARACTER** = **2** --- Character body. This behaves like a rigid body, but can not rotate.
  110. Description
  111. -----------
  112. Rigid body node. This node is used for placing rigid bodies in the scene. It can contain a number of shapes, and also shift mode between regular Rigid body, Kinematic, Character or Static.
  113. Member Function Description
  114. ---------------------------
  115. .. _class_RigidBody__integrate_forces:
  116. - void **_integrate_forces** **(** :ref:`PhysicsDirectBodyState<class_physicsdirectbodystate>` state **)** virtual
  117. 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_RigidBody_set_use_custom_integrator>` allows you to disable the default behavior and do fully custom force integration for a body.
  118. .. _class_RigidBody_apply_impulse:
  119. - void **apply_impulse** **(** :ref:`Vector3<class_vector3>` pos, :ref:`Vector3<class_vector3>` impulse **)**
  120. 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.
  121. .. _class_RigidBody_get_angular_damp:
  122. - :ref:`float<class_float>` **get_angular_damp** **(** **)** const
  123. Return the current body angular damp. Default is -1.
  124. .. _class_RigidBody_get_angular_velocity:
  125. - :ref:`Vector3<class_vector3>` **get_angular_velocity** **(** **)** const
  126. Return the current body angular velocity.
  127. .. _class_RigidBody_get_axis_lock:
  128. - :ref:`int<class_int>` **get_axis_lock** **(** **)** const
  129. Return the current axis lock of the body. One of AXIS_LOCK\_\* enum.
  130. .. _class_RigidBody_get_bounce:
  131. - :ref:`float<class_float>` **get_bounce** **(** **)** const
  132. Return the current body bounciness.
  133. .. _class_RigidBody_get_colliding_bodies:
  134. - :ref:`Array<class_array>` **get_colliding_bodies** **(** **)** const
  135. 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_RigidBody_set_max_contacts_reported>` to increase it.
  136. .. _class_RigidBody_get_friction:
  137. - :ref:`float<class_float>` **get_friction** **(** **)** const
  138. Return the current body friction, from 0 (frictionless) to 1 (max friction).
  139. .. _class_RigidBody_get_gravity_scale:
  140. - :ref:`float<class_float>` **get_gravity_scale** **(** **)** const
  141. Return the current body gravity scale.
  142. .. _class_RigidBody_get_linear_damp:
  143. - :ref:`float<class_float>` **get_linear_damp** **(** **)** const
  144. Return the current body linear damp. Default is -1.
  145. .. _class_RigidBody_get_linear_velocity:
  146. - :ref:`Vector3<class_vector3>` **get_linear_velocity** **(** **)** const
  147. Return the current body linear velocity.
  148. .. _class_RigidBody_get_mass:
  149. - :ref:`float<class_float>` **get_mass** **(** **)** const
  150. Return the current body mass.
  151. .. _class_RigidBody_get_max_contacts_reported:
  152. - :ref:`int<class_int>` **get_max_contacts_reported** **(** **)** const
  153. Return the maximum contacts that can be reported. See :ref:`set_max_contacts_reported<class_RigidBody_set_max_contacts_reported>`.
  154. .. _class_RigidBody_get_mode:
  155. - :ref:`int<class_int>` **get_mode** **(** **)** const
  156. Return the current body mode, see :ref:`set_mode<class_RigidBody_set_mode>`.
  157. .. _class_RigidBody_get_weight:
  158. - :ref:`float<class_float>` **get_weight** **(** **)** const
  159. Return the current body weight, given standard earth-weight (gravity 9.8).
  160. .. _class_RigidBody_is_able_to_sleep:
  161. - :ref:`bool<class_bool>` **is_able_to_sleep** **(** **)** const
  162. Return whether the body has the ability to fall asleep when not moving. See :ref:`set_can_sleep<class_RigidBody_set_can_sleep>`.
  163. .. _class_RigidBody_is_contact_monitor_enabled:
  164. - :ref:`bool<class_bool>` **is_contact_monitor_enabled** **(** **)** const
  165. Return whether contact monitoring is enabled.
  166. .. _class_RigidBody_is_sleeping:
  167. - :ref:`bool<class_bool>` **is_sleeping** **(** **)** const
  168. Return whether the body is sleeping.
  169. .. _class_RigidBody_is_using_continuous_collision_detection:
  170. - :ref:`bool<class_bool>` **is_using_continuous_collision_detection** **(** **)** const
  171. Return whether this body is using continuous collision detection.
  172. .. _class_RigidBody_is_using_custom_integrator:
  173. - :ref:`bool<class_bool>` **is_using_custom_integrator** **(** **)**
  174. Return whether the body is using a custom integrator.
  175. .. _class_RigidBody_set_angular_damp:
  176. - void **set_angular_damp** **(** :ref:`float<class_float>` angular_damp **)**
  177. Set the angular damp for this body. Default of -1, cannot be less than -1. If this value is different from -1, any angular damp derived from the world or areas will be overridden.
  178. .. _class_RigidBody_set_angular_velocity:
  179. - void **set_angular_velocity** **(** :ref:`Vector3<class_vector3>` angular_velocity **)**
  180. 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_RigidBody__integrate_forces>` as your process loop if you want to have precise control of the body state.
  181. .. _class_RigidBody_set_axis_lock:
  182. - void **set_axis_lock** **(** :ref:`int<class_int>` axis_lock **)**
  183. Set the axis lock of the body, from the AXIS_LOCK\_\* enum. Axis lock stops the body from moving along the specified axis(X/Y/Z) and rotating along the other two axes.
  184. .. _class_RigidBody_set_axis_velocity:
  185. - void **set_axis_velocity** **(** :ref:`Vector3<class_vector3>` axis_velocity **)**
  186. 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.
  187. .. _class_RigidBody_set_bounce:
  188. - void **set_bounce** **(** :ref:`float<class_float>` bounce **)**
  189. Set the body bounciness, from 0 (no bounciness) to 1 (max bounciness).
  190. .. _class_RigidBody_set_can_sleep:
  191. - void **set_can_sleep** **(** :ref:`bool<class_bool>` able_to_sleep **)**
  192. 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.
  193. Sleeping bodies are not affected by forces until a collision or an :ref:`apply_impulse<class_RigidBody_apply_impulse>` / :ref:`set_applied_force<class_RigidBody_set_applied_force>` wakes them up. Until then, they behave like a static body.
  194. .. _class_RigidBody_set_contact_monitor:
  195. - void **set_contact_monitor** **(** :ref:`bool<class_bool>` enabled **)**
  196. Enable contact monitoring. This allows the body to emit signals when it collides with another.
  197. .. _class_RigidBody_set_friction:
  198. - void **set_friction** **(** :ref:`float<class_float>` friction **)**
  199. Set the body friction, from 0 (frictionless) to 1 (max friction).
  200. .. _class_RigidBody_set_gravity_scale:
  201. - void **set_gravity_scale** **(** :ref:`float<class_float>` gravity_scale **)**
  202. Set the gravity factor. This factor multiplies gravity intensity just for this body.
  203. .. _class_RigidBody_set_linear_damp:
  204. - void **set_linear_damp** **(** :ref:`float<class_float>` linear_damp **)**
  205. Set the linear damp for this body. Default of -1, cannot be less than -1. If this value is different from -1, any linear damp derived from the world or areas will be overridden.
  206. .. _class_RigidBody_set_linear_velocity:
  207. - void **set_linear_velocity** **(** :ref:`Vector3<class_vector3>` linear_velocity **)**
  208. 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_RigidBody__integrate_forces>` as your process loop if you want to have precise control of the body state.
  209. .. _class_RigidBody_set_mass:
  210. - void **set_mass** **(** :ref:`float<class_float>` mass **)**
  211. Set the body mass.
  212. .. _class_RigidBody_set_max_contacts_reported:
  213. - void **set_max_contacts_reported** **(** :ref:`int<class_int>` amount **)**
  214. 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.
  215. .. _class_RigidBody_set_mode:
  216. - void **set_mode** **(** :ref:`int<class_int>` mode **)**
  217. Set the body mode, from the MODE\_\* enum. This allows to change to a static body or a character body.
  218. .. _class_RigidBody_set_sleeping:
  219. - void **set_sleeping** **(** :ref:`bool<class_bool>` sleeping **)**
  220. Set whether a body is sleeping or not. Sleeping bodies are not affected by forces until a collision or an :ref:`apply_impulse<class_RigidBody_apply_impulse>` wakes them up. Until then, they behave like a static body.
  221. .. _class_RigidBody_set_use_continuous_collision_detection:
  222. - void **set_use_continuous_collision_detection** **(** :ref:`bool<class_bool>` enable **)**
  223. Set the continuous collision detection mode from the enum CCD_MODE\_\*.
  224. 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.
  225. .. _class_RigidBody_set_use_custom_integrator:
  226. - void **set_use_custom_integrator** **(** :ref:`bool<class_bool>` enable **)**
  227. 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_RigidBody__integrate_forces>` function, if defined.
  228. .. _class_RigidBody_set_weight:
  229. - void **set_weight** **(** :ref:`float<class_float>` weight **)**
  230. Set the body weight given standard earth-weight (gravity 9.8).