class_rigidbody.rst 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/RigidBody.xml.
  6. .. _class_RigidBody:
  7. RigidBody
  8. =========
  9. **Inherits:** :ref:`PhysicsBody<class_PhysicsBody>` **<** :ref:`CollisionObject<class_CollisionObject>` **<** :ref:`Spatial<class_Spatial>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`VehicleBody<class_VehicleBody>`
  11. Physics Body whose position is determined through physics simulation in 3D space.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. This is the node that implements full 3D physics. This means that you do not control a RigidBody directly. Instead, you can apply forces to it (gravity, impulses, etc.), and the physics simulation will calculate the resulting movement, collision, bouncing, rotating, etc.
  16. A RigidBody has 4 behavior :ref:`mode<class_RigidBody_property_mode>`\ s: Rigid, Static, Character, and Kinematic.
  17. \ **Note:** Don't change a RigidBody's 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 may result in strange behavior. If you need to directly affect the body's state, use :ref:`_integrate_forces<class_RigidBody_method__integrate_forces>`, which allows you to directly access the physics state.
  18. If you need to override the default physics behavior, you can write a custom force integration function. See :ref:`custom_integrator<class_RigidBody_property_custom_integrator>`.
  19. With Bullet physics (the default), the center of mass is the RigidBody3D center. With GodotPhysics, the center of mass is the average of the :ref:`CollisionShape<class_CollisionShape>` centers.
  20. \ **Warning:** With a non-uniform scale this node will probably not function as expected. Please make sure to keep its scale uniform (i.e. the same on all axes), and change the size(s) of its collision shape(s) instead.
  21. .. rst-class:: classref-introduction-group
  22. Tutorials
  23. ---------
  24. - :doc:`Physics introduction <../tutorials/physics/physics_introduction>`
  25. - `3D Truck Town Demo <https://godotengine.org/asset-library/asset/524>`__
  26. - `3D Physics Tests Demo <https://godotengine.org/asset-library/asset/675>`__
  27. .. rst-class:: classref-reftable-group
  28. Properties
  29. ----------
  30. .. table::
  31. :widths: auto
  32. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  33. | :ref:`float<class_float>` | :ref:`angular_damp<class_RigidBody_property_angular_damp>` | ``-1.0`` |
  34. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  35. | :ref:`Vector3<class_Vector3>` | :ref:`angular_velocity<class_RigidBody_property_angular_velocity>` | ``Vector3( 0, 0, 0 )`` |
  36. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  37. | :ref:`bool<class_bool>` | :ref:`axis_lock_angular_x<class_RigidBody_property_axis_lock_angular_x>` | ``false`` |
  38. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  39. | :ref:`bool<class_bool>` | :ref:`axis_lock_angular_y<class_RigidBody_property_axis_lock_angular_y>` | ``false`` |
  40. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`axis_lock_angular_z<class_RigidBody_property_axis_lock_angular_z>` | ``false`` |
  42. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`axis_lock_linear_x<class_RigidBody_property_axis_lock_linear_x>` | ``false`` |
  44. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`axis_lock_linear_y<class_RigidBody_property_axis_lock_linear_y>` | ``false`` |
  46. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`axis_lock_linear_z<class_RigidBody_property_axis_lock_linear_z>` | ``false`` |
  48. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  49. | :ref:`float<class_float>` | :ref:`bounce<class_RigidBody_property_bounce>` | |
  50. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  51. | :ref:`bool<class_bool>` | :ref:`can_sleep<class_RigidBody_property_can_sleep>` | ``true`` |
  52. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`contact_monitor<class_RigidBody_property_contact_monitor>` | ``false`` |
  54. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  55. | :ref:`int<class_int>` | :ref:`contacts_reported<class_RigidBody_property_contacts_reported>` | ``0`` |
  56. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`continuous_cd<class_RigidBody_property_continuous_cd>` | ``false`` |
  58. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`custom_integrator<class_RigidBody_property_custom_integrator>` | ``false`` |
  60. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  61. | :ref:`float<class_float>` | :ref:`friction<class_RigidBody_property_friction>` | |
  62. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  63. | :ref:`float<class_float>` | :ref:`gravity_scale<class_RigidBody_property_gravity_scale>` | ``1.0`` |
  64. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  65. | :ref:`float<class_float>` | :ref:`linear_damp<class_RigidBody_property_linear_damp>` | ``-1.0`` |
  66. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  67. | :ref:`Vector3<class_Vector3>` | :ref:`linear_velocity<class_RigidBody_property_linear_velocity>` | ``Vector3( 0, 0, 0 )`` |
  68. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  69. | :ref:`float<class_float>` | :ref:`mass<class_RigidBody_property_mass>` | ``1.0`` |
  70. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  71. | :ref:`Mode<enum_RigidBody_Mode>` | :ref:`mode<class_RigidBody_property_mode>` | ``0`` |
  72. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  73. | :ref:`PhysicsMaterial<class_PhysicsMaterial>` | :ref:`physics_material_override<class_RigidBody_property_physics_material_override>` | |
  74. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  75. | :ref:`bool<class_bool>` | :ref:`sleeping<class_RigidBody_property_sleeping>` | ``false`` |
  76. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  77. | :ref:`float<class_float>` | :ref:`weight<class_RigidBody_property_weight>` | ``9.8`` |
  78. +-----------------------------------------------+--------------------------------------------------------------------------------------+------------------------+
  79. .. rst-class:: classref-reftable-group
  80. Methods
  81. -------
  82. .. table::
  83. :widths: auto
  84. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | void | :ref:`_integrate_forces<class_RigidBody_method__integrate_forces>` **(** :ref:`PhysicsDirectBodyState<class_PhysicsDirectBodyState>` state **)** |virtual| |
  86. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | void | :ref:`add_central_force<class_RigidBody_method_add_central_force>` **(** :ref:`Vector3<class_Vector3>` force **)** |
  88. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | void | :ref:`add_force<class_RigidBody_method_add_force>` **(** :ref:`Vector3<class_Vector3>` force, :ref:`Vector3<class_Vector3>` position **)** |
  90. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | void | :ref:`add_torque<class_RigidBody_method_add_torque>` **(** :ref:`Vector3<class_Vector3>` torque **)** |
  92. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | void | :ref:`apply_central_impulse<class_RigidBody_method_apply_central_impulse>` **(** :ref:`Vector3<class_Vector3>` impulse **)** |
  94. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | void | :ref:`apply_impulse<class_RigidBody_method_apply_impulse>` **(** :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` impulse **)** |
  96. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | void | :ref:`apply_torque_impulse<class_RigidBody_method_apply_torque_impulse>` **(** :ref:`Vector3<class_Vector3>` impulse **)** |
  98. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`bool<class_bool>` | :ref:`get_axis_lock<class_RigidBody_method_get_axis_lock>` **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis **)** |const| |
  100. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`Array<class_Array>` | :ref:`get_colliding_bodies<class_RigidBody_method_get_colliding_bodies>` **(** **)** |const| |
  102. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`Basis<class_Basis>` | :ref:`get_inverse_inertia_tensor<class_RigidBody_method_get_inverse_inertia_tensor>` **(** **)** |
  104. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | void | :ref:`set_axis_lock<class_RigidBody_method_set_axis_lock>` **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)** |
  106. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | void | :ref:`set_axis_velocity<class_RigidBody_method_set_axis_velocity>` **(** :ref:`Vector3<class_Vector3>` axis_velocity **)** |
  108. +---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. .. rst-class:: classref-section-separator
  110. ----
  111. .. rst-class:: classref-descriptions-group
  112. Signals
  113. -------
  114. .. _class_RigidBody_signal_body_entered:
  115. .. rst-class:: classref-signal
  116. **body_entered** **(** :ref:`Node<class_Node>` body **)**
  117. Emitted when a collision with another :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>` occurs. Requires :ref:`contact_monitor<class_RigidBody_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidBody_property_contacts_reported>` to be set high enough to detect all the collisions. :ref:`GridMap<class_GridMap>`\ s are detected if the :ref:`MeshLibrary<class_MeshLibrary>` has Collision :ref:`Shape<class_Shape>`\ s.
  118. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>`.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_RigidBody_signal_body_exited:
  122. .. rst-class:: classref-signal
  123. **body_exited** **(** :ref:`Node<class_Node>` body **)**
  124. Emitted when the collision with another :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>` ends. Requires :ref:`contact_monitor<class_RigidBody_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidBody_property_contacts_reported>` to be set high enough to detect all the collisions. :ref:`GridMap<class_GridMap>`\ s are detected if the :ref:`MeshLibrary<class_MeshLibrary>` has Collision :ref:`Shape<class_Shape>`\ s.
  125. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>`.
  126. .. rst-class:: classref-item-separator
  127. ----
  128. .. _class_RigidBody_signal_body_shape_entered:
  129. .. rst-class:: classref-signal
  130. **body_shape_entered** **(** :ref:`RID<class_RID>` body_rid, :ref:`Node<class_Node>` body, :ref:`int<class_int>` body_shape_index, :ref:`int<class_int>` local_shape_index **)**
  131. Emitted when one of this RigidBody's :ref:`Shape<class_Shape>`\ s collides with another :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>`'s :ref:`Shape<class_Shape>`\ s. Requires :ref:`contact_monitor<class_RigidBody_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidBody_property_contacts_reported>` to be set high enough to detect all the collisions. :ref:`GridMap<class_GridMap>`\ s are detected if the :ref:`MeshLibrary<class_MeshLibrary>` has Collision :ref:`Shape<class_Shape>`\ s.
  132. \ ``body_rid`` the :ref:`RID<class_RID>` of the other :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`MeshLibrary<class_MeshLibrary>`'s :ref:`CollisionObject<class_CollisionObject>` used by the :ref:`PhysicsServer<class_PhysicsServer>`.
  133. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>`.
  134. \ ``body_shape_index`` the index of the :ref:`Shape<class_Shape>` of the other :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>`.
  135. \ ``local_shape_index`` the index of the :ref:`Shape<class_Shape>` of this RigidBody.
  136. \ **Example of getting the** :ref:`CollisionShape<class_CollisionShape>` **node from the shape index:**\
  137. ::
  138. var body_shape_owner = body.shape_find_owner(body_shape_index)
  139. var body_shape_node = body.shape_owner_get_owner(body_shape_owner)
  140. var local_shape_owner = shape_find_owner(local_shape_index)
  141. var local_shape_node = shape_owner_get_owner(local_shape_owner)
  142. \ **Note:** Bullet physics cannot identify the shape index when using a :ref:`ConcavePolygonShape<class_ConcavePolygonShape>`. Don't use multiple :ref:`CollisionShape<class_CollisionShape>`\ s when using a :ref:`ConcavePolygonShape<class_ConcavePolygonShape>` with Bullet physics if you need shape indices.
  143. .. rst-class:: classref-item-separator
  144. ----
  145. .. _class_RigidBody_signal_body_shape_exited:
  146. .. rst-class:: classref-signal
  147. **body_shape_exited** **(** :ref:`RID<class_RID>` body_rid, :ref:`Node<class_Node>` body, :ref:`int<class_int>` body_shape_index, :ref:`int<class_int>` local_shape_index **)**
  148. Emitted when the collision between one of this RigidBody's :ref:`Shape<class_Shape>`\ s and another :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>`'s :ref:`Shape<class_Shape>`\ s ends. Requires :ref:`contact_monitor<class_RigidBody_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidBody_property_contacts_reported>` to be set high enough to detect all the collisions. :ref:`GridMap<class_GridMap>`\ s are detected if the :ref:`MeshLibrary<class_MeshLibrary>` has Collision :ref:`Shape<class_Shape>`\ s.
  149. \ ``body_rid`` the :ref:`RID<class_RID>` of the other :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`MeshLibrary<class_MeshLibrary>`'s :ref:`CollisionObject<class_CollisionObject>` used by the :ref:`PhysicsServer<class_PhysicsServer>`. :ref:`GridMap<class_GridMap>`\ s are detected if the Meshes have :ref:`Shape<class_Shape>`\ s.
  150. \ ``body`` the :ref:`Node<class_Node>`, if it exists in the tree, of the other :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>`.
  151. \ ``body_shape_index`` the index of the :ref:`Shape<class_Shape>` of the other :ref:`PhysicsBody<class_PhysicsBody>` or :ref:`GridMap<class_GridMap>`.
  152. \ ``local_shape_index`` the index of the :ref:`Shape<class_Shape>` of this RigidBody.
  153. \ **Note:** Bullet physics cannot identify the shape index when using a :ref:`ConcavePolygonShape<class_ConcavePolygonShape>`. Don't use multiple :ref:`CollisionShape<class_CollisionShape>`\ s when using a :ref:`ConcavePolygonShape<class_ConcavePolygonShape>` with Bullet physics if you need shape indices.
  154. See also :ref:`body_shape_entered<class_RigidBody_signal_body_shape_entered>`.
  155. .. rst-class:: classref-item-separator
  156. ----
  157. .. _class_RigidBody_signal_sleeping_state_changed:
  158. .. rst-class:: classref-signal
  159. **sleeping_state_changed** **(** **)**
  160. Emitted when the physics engine changes the body's sleeping state.
  161. \ **Note:** Changing the value :ref:`sleeping<class_RigidBody_property_sleeping>` will not trigger this signal. It is only emitted if the sleeping state is changed by the physics engine or ``emit_signal("sleeping_state_changed")`` is used.
  162. .. rst-class:: classref-section-separator
  163. ----
  164. .. rst-class:: classref-descriptions-group
  165. Enumerations
  166. ------------
  167. .. _enum_RigidBody_Mode:
  168. .. rst-class:: classref-enumeration
  169. enum **Mode**:
  170. .. _class_RigidBody_constant_MODE_RIGID:
  171. .. rst-class:: classref-enumeration-constant
  172. :ref:`Mode<enum_RigidBody_Mode>` **MODE_RIGID** = ``0``
  173. Rigid body mode. This is the "natural" state of a rigid body. It is affected by forces, and can move, rotate, and be affected by user code.
  174. .. _class_RigidBody_constant_MODE_STATIC:
  175. .. rst-class:: classref-enumeration-constant
  176. :ref:`Mode<enum_RigidBody_Mode>` **MODE_STATIC** = ``1``
  177. Static mode. The body behaves like a :ref:`StaticBody<class_StaticBody>`, and can only move by user code.
  178. .. _class_RigidBody_constant_MODE_CHARACTER:
  179. .. rst-class:: classref-enumeration-constant
  180. :ref:`Mode<enum_RigidBody_Mode>` **MODE_CHARACTER** = ``2``
  181. Character body mode. This behaves like a rigid body, but can not rotate.
  182. .. _class_RigidBody_constant_MODE_KINEMATIC:
  183. .. rst-class:: classref-enumeration-constant
  184. :ref:`Mode<enum_RigidBody_Mode>` **MODE_KINEMATIC** = ``3``
  185. Kinematic body mode. The body behaves like a :ref:`KinematicBody<class_KinematicBody>`, and can only move by user code.
  186. .. rst-class:: classref-section-separator
  187. ----
  188. .. rst-class:: classref-descriptions-group
  189. Property Descriptions
  190. ---------------------
  191. .. _class_RigidBody_property_angular_damp:
  192. .. rst-class:: classref-property
  193. :ref:`float<class_float>` **angular_damp** = ``-1.0``
  194. .. rst-class:: classref-property-setget
  195. - void **set_angular_damp** **(** :ref:`float<class_float>` value **)**
  196. - :ref:`float<class_float>` **get_angular_damp** **(** **)**
  197. Damps the body's rotational forces. If this value is different from -1.0 it will be added to any angular damp derived from the world or areas.
  198. See :ref:`ProjectSettings.physics/3d/default_angular_damp<class_ProjectSettings_property_physics/3d/default_angular_damp>` for more details about damping.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_RigidBody_property_angular_velocity:
  202. .. rst-class:: classref-property
  203. :ref:`Vector3<class_Vector3>` **angular_velocity** = ``Vector3( 0, 0, 0 )``
  204. .. rst-class:: classref-property-setget
  205. - void **set_angular_velocity** **(** :ref:`Vector3<class_Vector3>` value **)**
  206. - :ref:`Vector3<class_Vector3>` **get_angular_velocity** **(** **)**
  207. The body's rotational velocity in axis-angle format. The magnitude of the vector is the rotation rate in *radians* per second.
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. _class_RigidBody_property_axis_lock_angular_x:
  211. .. rst-class:: classref-property
  212. :ref:`bool<class_bool>` **axis_lock_angular_x** = ``false``
  213. .. rst-class:: classref-property-setget
  214. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  215. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis **)** |const|
  216. Lock the body's rotation in the X axis.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_RigidBody_property_axis_lock_angular_y:
  220. .. rst-class:: classref-property
  221. :ref:`bool<class_bool>` **axis_lock_angular_y** = ``false``
  222. .. rst-class:: classref-property-setget
  223. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  224. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis **)** |const|
  225. Lock the body's rotation in the Y axis.
  226. .. rst-class:: classref-item-separator
  227. ----
  228. .. _class_RigidBody_property_axis_lock_angular_z:
  229. .. rst-class:: classref-property
  230. :ref:`bool<class_bool>` **axis_lock_angular_z** = ``false``
  231. .. rst-class:: classref-property-setget
  232. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  233. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis **)** |const|
  234. Lock the body's rotation in the Z axis.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_RigidBody_property_axis_lock_linear_x:
  238. .. rst-class:: classref-property
  239. :ref:`bool<class_bool>` **axis_lock_linear_x** = ``false``
  240. .. rst-class:: classref-property-setget
  241. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  242. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis **)** |const|
  243. Lock the body's movement in the X axis.
  244. .. rst-class:: classref-item-separator
  245. ----
  246. .. _class_RigidBody_property_axis_lock_linear_y:
  247. .. rst-class:: classref-property
  248. :ref:`bool<class_bool>` **axis_lock_linear_y** = ``false``
  249. .. rst-class:: classref-property-setget
  250. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  251. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis **)** |const|
  252. Lock the body's movement in the Y axis.
  253. .. rst-class:: classref-item-separator
  254. ----
  255. .. _class_RigidBody_property_axis_lock_linear_z:
  256. .. rst-class:: classref-property
  257. :ref:`bool<class_bool>` **axis_lock_linear_z** = ``false``
  258. .. rst-class:: classref-property-setget
  259. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  260. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis **)** |const|
  261. Lock the body's movement in the Z axis.
  262. .. rst-class:: classref-item-separator
  263. ----
  264. .. _class_RigidBody_property_bounce:
  265. .. rst-class:: classref-property
  266. :ref:`float<class_float>` **bounce**
  267. .. rst-class:: classref-property-setget
  268. - void **set_bounce** **(** :ref:`float<class_float>` value **)**
  269. - :ref:`float<class_float>` **get_bounce** **(** **)**
  270. The body's bounciness. Values range from ``0`` (no bounce) to ``1`` (full bounciness).
  271. Deprecated, use :ref:`PhysicsMaterial.bounce<class_PhysicsMaterial_property_bounce>` instead via :ref:`physics_material_override<class_RigidBody_property_physics_material_override>`.
  272. .. rst-class:: classref-item-separator
  273. ----
  274. .. _class_RigidBody_property_can_sleep:
  275. .. rst-class:: classref-property
  276. :ref:`bool<class_bool>` **can_sleep** = ``true``
  277. .. rst-class:: classref-property-setget
  278. - void **set_can_sleep** **(** :ref:`bool<class_bool>` value **)**
  279. - :ref:`bool<class_bool>` **is_able_to_sleep** **(** **)**
  280. If ``true``, the body can enter sleep mode when there is no movement. See :ref:`sleeping<class_RigidBody_property_sleeping>`.
  281. \ **Note:** A RigidBody3D will never enter sleep mode automatically if its :ref:`mode<class_RigidBody_property_mode>` is :ref:`MODE_CHARACTER<class_RigidBody_constant_MODE_CHARACTER>`. It can still be put to sleep manually by setting its :ref:`sleeping<class_RigidBody_property_sleeping>` property to ``true``.
  282. .. rst-class:: classref-item-separator
  283. ----
  284. .. _class_RigidBody_property_contact_monitor:
  285. .. rst-class:: classref-property
  286. :ref:`bool<class_bool>` **contact_monitor** = ``false``
  287. .. rst-class:: classref-property-setget
  288. - void **set_contact_monitor** **(** :ref:`bool<class_bool>` value **)**
  289. - :ref:`bool<class_bool>` **is_contact_monitor_enabled** **(** **)**
  290. If ``true``, the RigidBody will emit signals when it collides with another RigidBody. See also :ref:`contacts_reported<class_RigidBody_property_contacts_reported>`.
  291. .. rst-class:: classref-item-separator
  292. ----
  293. .. _class_RigidBody_property_contacts_reported:
  294. .. rst-class:: classref-property
  295. :ref:`int<class_int>` **contacts_reported** = ``0``
  296. .. rst-class:: classref-property-setget
  297. - void **set_max_contacts_reported** **(** :ref:`int<class_int>` value **)**
  298. - :ref:`int<class_int>` **get_max_contacts_reported** **(** **)**
  299. The maximum number of contacts that will be recorded. Requires :ref:`contact_monitor<class_RigidBody_property_contact_monitor>` to be set to ``true``.
  300. \ **Note:** The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end), and collisions between parallel faces will result in four contacts (one at each corner).
  301. .. rst-class:: classref-item-separator
  302. ----
  303. .. _class_RigidBody_property_continuous_cd:
  304. .. rst-class:: classref-property
  305. :ref:`bool<class_bool>` **continuous_cd** = ``false``
  306. .. rst-class:: classref-property-setget
  307. - void **set_use_continuous_collision_detection** **(** :ref:`bool<class_bool>` value **)**
  308. - :ref:`bool<class_bool>` **is_using_continuous_collision_detection** **(** **)**
  309. If ``true``, continuous collision detection is used.
  310. Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided. Continuous collision detection is more precise, and misses fewer impacts by small, fast-moving objects. Not using continuous collision detection is faster to compute, but can miss small, fast-moving objects.
  311. .. rst-class:: classref-item-separator
  312. ----
  313. .. _class_RigidBody_property_custom_integrator:
  314. .. rst-class:: classref-property
  315. :ref:`bool<class_bool>` **custom_integrator** = ``false``
  316. .. rst-class:: classref-property-setget
  317. - void **set_use_custom_integrator** **(** :ref:`bool<class_bool>` value **)**
  318. - :ref:`bool<class_bool>` **is_using_custom_integrator** **(** **)**
  319. If ``true``, internal force integration will be disabled (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_method__integrate_forces>` function, if defined.
  320. .. rst-class:: classref-item-separator
  321. ----
  322. .. _class_RigidBody_property_friction:
  323. .. rst-class:: classref-property
  324. :ref:`float<class_float>` **friction**
  325. .. rst-class:: classref-property-setget
  326. - void **set_friction** **(** :ref:`float<class_float>` value **)**
  327. - :ref:`float<class_float>` **get_friction** **(** **)**
  328. The body's friction, from 0 (frictionless) to 1 (max friction).
  329. Deprecated, use :ref:`PhysicsMaterial.friction<class_PhysicsMaterial_property_friction>` instead via :ref:`physics_material_override<class_RigidBody_property_physics_material_override>`.
  330. .. rst-class:: classref-item-separator
  331. ----
  332. .. _class_RigidBody_property_gravity_scale:
  333. .. rst-class:: classref-property
  334. :ref:`float<class_float>` **gravity_scale** = ``1.0``
  335. .. rst-class:: classref-property-setget
  336. - void **set_gravity_scale** **(** :ref:`float<class_float>` value **)**
  337. - :ref:`float<class_float>` **get_gravity_scale** **(** **)**
  338. This is multiplied by the global 3D gravity setting found in **Project > Project Settings > Physics > 3d** to produce RigidBody's gravity. For example, a value of 1 will be normal gravity, 2 will apply double gravity, and 0.5 will apply half gravity to this object.
  339. .. rst-class:: classref-item-separator
  340. ----
  341. .. _class_RigidBody_property_linear_damp:
  342. .. rst-class:: classref-property
  343. :ref:`float<class_float>` **linear_damp** = ``-1.0``
  344. .. rst-class:: classref-property-setget
  345. - void **set_linear_damp** **(** :ref:`float<class_float>` value **)**
  346. - :ref:`float<class_float>` **get_linear_damp** **(** **)**
  347. The body's linear damp. Cannot be less than -1.0. If this value is different from -1.0 it will be added to any linear damp derived from the world or areas.
  348. See :ref:`ProjectSettings.physics/3d/default_linear_damp<class_ProjectSettings_property_physics/3d/default_linear_damp>` for more details about damping.
  349. .. rst-class:: classref-item-separator
  350. ----
  351. .. _class_RigidBody_property_linear_velocity:
  352. .. rst-class:: classref-property
  353. :ref:`Vector3<class_Vector3>` **linear_velocity** = ``Vector3( 0, 0, 0 )``
  354. .. rst-class:: classref-property-setget
  355. - void **set_linear_velocity** **(** :ref:`Vector3<class_Vector3>` value **)**
  356. - :ref:`Vector3<class_Vector3>` **get_linear_velocity** **(** **)**
  357. The body's linear velocity in units per second. Can be used sporadically, but **don't set this every frame**, because physics may run in another thread and runs at a different granularity. Use :ref:`_integrate_forces<class_RigidBody_method__integrate_forces>` as your process loop for precise control of the body state.
  358. .. rst-class:: classref-item-separator
  359. ----
  360. .. _class_RigidBody_property_mass:
  361. .. rst-class:: classref-property
  362. :ref:`float<class_float>` **mass** = ``1.0``
  363. .. rst-class:: classref-property-setget
  364. - void **set_mass** **(** :ref:`float<class_float>` value **)**
  365. - :ref:`float<class_float>` **get_mass** **(** **)**
  366. The body's mass.
  367. .. rst-class:: classref-item-separator
  368. ----
  369. .. _class_RigidBody_property_mode:
  370. .. rst-class:: classref-property
  371. :ref:`Mode<enum_RigidBody_Mode>` **mode** = ``0``
  372. .. rst-class:: classref-property-setget
  373. - void **set_mode** **(** :ref:`Mode<enum_RigidBody_Mode>` value **)**
  374. - :ref:`Mode<enum_RigidBody_Mode>` **get_mode** **(** **)**
  375. The body mode. See :ref:`Mode<enum_RigidBody_Mode>` for possible values.
  376. .. rst-class:: classref-item-separator
  377. ----
  378. .. _class_RigidBody_property_physics_material_override:
  379. .. rst-class:: classref-property
  380. :ref:`PhysicsMaterial<class_PhysicsMaterial>` **physics_material_override**
  381. .. rst-class:: classref-property-setget
  382. - void **set_physics_material_override** **(** :ref:`PhysicsMaterial<class_PhysicsMaterial>` value **)**
  383. - :ref:`PhysicsMaterial<class_PhysicsMaterial>` **get_physics_material_override** **(** **)**
  384. The physics material override for the body.
  385. If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one.
  386. .. rst-class:: classref-item-separator
  387. ----
  388. .. _class_RigidBody_property_sleeping:
  389. .. rst-class:: classref-property
  390. :ref:`bool<class_bool>` **sleeping** = ``false``
  391. .. rst-class:: classref-property-setget
  392. - void **set_sleeping** **(** :ref:`bool<class_bool>` value **)**
  393. - :ref:`bool<class_bool>` **is_sleeping** **(** **)**
  394. If ``true``, the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the :ref:`apply_impulse<class_RigidBody_method_apply_impulse>` or :ref:`add_force<class_RigidBody_method_add_force>` methods.
  395. .. rst-class:: classref-item-separator
  396. ----
  397. .. _class_RigidBody_property_weight:
  398. .. rst-class:: classref-property
  399. :ref:`float<class_float>` **weight** = ``9.8``
  400. .. rst-class:: classref-property-setget
  401. - void **set_weight** **(** :ref:`float<class_float>` value **)**
  402. - :ref:`float<class_float>` **get_weight** **(** **)**
  403. The body's weight based on its mass and the global 3D gravity. Global values are set in **Project > Project Settings > Physics > 3d**.
  404. .. rst-class:: classref-section-separator
  405. ----
  406. .. rst-class:: classref-descriptions-group
  407. Method Descriptions
  408. -------------------
  409. .. _class_RigidBody_method__integrate_forces:
  410. .. rst-class:: classref-method
  411. void **_integrate_forces** **(** :ref:`PhysicsDirectBodyState<class_PhysicsDirectBodyState>` state **)** |virtual|
  412. 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 the :ref:`custom_integrator<class_RigidBody_property_custom_integrator>` property allows you to disable the default behavior and do fully custom force integration for a body.
  413. .. rst-class:: classref-item-separator
  414. ----
  415. .. _class_RigidBody_method_add_central_force:
  416. .. rst-class:: classref-method
  417. void **add_central_force** **(** :ref:`Vector3<class_Vector3>` force **)**
  418. Adds a constant directional force (i.e. acceleration) without affecting rotation.
  419. This is equivalent to ``add_force(force, Vector3(0,0,0))``.
  420. .. rst-class:: classref-item-separator
  421. ----
  422. .. _class_RigidBody_method_add_force:
  423. .. rst-class:: classref-method
  424. void **add_force** **(** :ref:`Vector3<class_Vector3>` force, :ref:`Vector3<class_Vector3>` position **)**
  425. Adds a constant directional force (i.e. acceleration).
  426. The position uses the rotation of the global coordinate system, but is centered at the object's origin.
  427. .. rst-class:: classref-item-separator
  428. ----
  429. .. _class_RigidBody_method_add_torque:
  430. .. rst-class:: classref-method
  431. void **add_torque** **(** :ref:`Vector3<class_Vector3>` torque **)**
  432. Adds a constant rotational force (i.e. a motor) without affecting position.
  433. .. rst-class:: classref-item-separator
  434. ----
  435. .. _class_RigidBody_method_apply_central_impulse:
  436. .. rst-class:: classref-method
  437. void **apply_central_impulse** **(** :ref:`Vector3<class_Vector3>` impulse **)**
  438. Applies a directional impulse without affecting rotation.
  439. This is equivalent to ``apply_impulse(Vector3(0,0,0), impulse)``.
  440. .. rst-class:: classref-item-separator
  441. ----
  442. .. _class_RigidBody_method_apply_impulse:
  443. .. rst-class:: classref-method
  444. void **apply_impulse** **(** :ref:`Vector3<class_Vector3>` position, :ref:`Vector3<class_Vector3>` impulse **)**
  445. 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. The position uses the rotation of the global coordinate system, but is centered at the object's origin.
  446. .. rst-class:: classref-item-separator
  447. ----
  448. .. _class_RigidBody_method_apply_torque_impulse:
  449. .. rst-class:: classref-method
  450. void **apply_torque_impulse** **(** :ref:`Vector3<class_Vector3>` impulse **)**
  451. Applies a torque impulse which will be affected by the body mass and shape. This will rotate the body around the ``impulse`` vector passed.
  452. .. rst-class:: classref-item-separator
  453. ----
  454. .. _class_RigidBody_method_get_axis_lock:
  455. .. rst-class:: classref-method
  456. :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis **)** |const|
  457. Returns ``true`` if the specified linear or rotational axis is locked.
  458. .. rst-class:: classref-item-separator
  459. ----
  460. .. _class_RigidBody_method_get_colliding_bodies:
  461. .. rst-class:: classref-method
  462. :ref:`Array<class_Array>` **get_colliding_bodies** **(** **)** |const|
  463. Returns a list of the bodies colliding with this one. Requires :ref:`contact_monitor<class_RigidBody_property_contact_monitor>` to be set to ``true`` and :ref:`contacts_reported<class_RigidBody_property_contacts_reported>` to be set high enough to detect all the collisions.
  464. \ **Note:** The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.
  465. .. rst-class:: classref-item-separator
  466. ----
  467. .. _class_RigidBody_method_get_inverse_inertia_tensor:
  468. .. rst-class:: classref-method
  469. :ref:`Basis<class_Basis>` **get_inverse_inertia_tensor** **(** **)**
  470. Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration resulting from a torque applied to the RigidBody.
  471. .. rst-class:: classref-item-separator
  472. ----
  473. .. _class_RigidBody_method_set_axis_lock:
  474. .. rst-class:: classref-method
  475. void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  476. Locks the specified linear or rotational axis.
  477. .. rst-class:: classref-item-separator
  478. ----
  479. .. _class_RigidBody_method_set_axis_velocity:
  480. .. rst-class:: classref-method
  481. void **set_axis_velocity** **(** :ref:`Vector3<class_Vector3>` axis_velocity **)**
  482. Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
  483. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  484. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  485. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  486. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`