class_physicsbody3d.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/PhysicsBody3D.xml.
  6. .. _class_PhysicsBody3D:
  7. PhysicsBody3D
  8. =============
  9. **Inherits:** :ref:`CollisionObject3D<class_CollisionObject3D>` **<** :ref:`Node3D<class_Node3D>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`CharacterBody3D<class_CharacterBody3D>`, :ref:`PhysicalBone3D<class_PhysicalBone3D>`, :ref:`RigidBody3D<class_RigidBody3D>`, :ref:`StaticBody3D<class_StaticBody3D>`
  11. Abstract base class for 3D game objects affected by physics.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. **PhysicsBody3D** is an abstract base class for 3D game objects affected by physics. All 3D physics bodies inherit from it.
  16. \ **Warning:** With a non-uniform scale, this node will likely not behave as expected. It is advised to keep its scale the same on all axes and adjust its collision shape(s) instead.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`Physics introduction <../tutorials/physics/physics_introduction>`
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +-------------------------+------------------------------------------------------------------------------+-----------+
  27. | :ref:`bool<class_bool>` | :ref:`axis_lock_angular_x<class_PhysicsBody3D_property_axis_lock_angular_x>` | ``false`` |
  28. +-------------------------+------------------------------------------------------------------------------+-----------+
  29. | :ref:`bool<class_bool>` | :ref:`axis_lock_angular_y<class_PhysicsBody3D_property_axis_lock_angular_y>` | ``false`` |
  30. +-------------------------+------------------------------------------------------------------------------+-----------+
  31. | :ref:`bool<class_bool>` | :ref:`axis_lock_angular_z<class_PhysicsBody3D_property_axis_lock_angular_z>` | ``false`` |
  32. +-------------------------+------------------------------------------------------------------------------+-----------+
  33. | :ref:`bool<class_bool>` | :ref:`axis_lock_linear_x<class_PhysicsBody3D_property_axis_lock_linear_x>` | ``false`` |
  34. +-------------------------+------------------------------------------------------------------------------+-----------+
  35. | :ref:`bool<class_bool>` | :ref:`axis_lock_linear_y<class_PhysicsBody3D_property_axis_lock_linear_y>` | ``false`` |
  36. +-------------------------+------------------------------------------------------------------------------+-----------+
  37. | :ref:`bool<class_bool>` | :ref:`axis_lock_linear_z<class_PhysicsBody3D_property_axis_lock_linear_z>` | ``false`` |
  38. +-------------------------+------------------------------------------------------------------------------+-----------+
  39. .. rst-class:: classref-reftable-group
  40. Methods
  41. -------
  42. .. table::
  43. :widths: auto
  44. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`add_collision_exception_with<class_PhysicsBody3D_method_add_collision_exception_with>` **(** :ref:`Node<class_Node>` body **)** |
  46. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`get_axis_lock<class_PhysicsBody3D_method_get_axis_lock>` **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis **)** |const| |
  48. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`PhysicsBody3D[]<class_PhysicsBody3D>` | :ref:`get_collision_exceptions<class_PhysicsBody3D_method_get_collision_exceptions>` **(** **)** |
  50. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`KinematicCollision3D<class_KinematicCollision3D>` | :ref:`move_and_collide<class_PhysicsBody3D_method_move_and_collide>` **(** :ref:`Vector3<class_Vector3>` motion, :ref:`bool<class_bool>` test_only=false, :ref:`float<class_float>` safe_margin=0.001, :ref:`bool<class_bool>` recovery_as_collision=false, :ref:`int<class_int>` max_collisions=1 **)** |
  52. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`remove_collision_exception_with<class_PhysicsBody3D_method_remove_collision_exception_with>` **(** :ref:`Node<class_Node>` body **)** |
  54. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_axis_lock<class_PhysicsBody3D_method_set_axis_lock>` **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)** |
  56. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`bool<class_bool>` | :ref:`test_move<class_PhysicsBody3D_method_test_move>` **(** :ref:`Transform3D<class_Transform3D>` from, :ref:`Vector3<class_Vector3>` motion, :ref:`KinematicCollision3D<class_KinematicCollision3D>` collision=null, :ref:`float<class_float>` safe_margin=0.001, :ref:`bool<class_bool>` recovery_as_collision=false, :ref:`int<class_int>` max_collisions=1 **)** |
  58. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. .. rst-class:: classref-section-separator
  60. ----
  61. .. rst-class:: classref-descriptions-group
  62. Property Descriptions
  63. ---------------------
  64. .. _class_PhysicsBody3D_property_axis_lock_angular_x:
  65. .. rst-class:: classref-property
  66. :ref:`bool<class_bool>` **axis_lock_angular_x** = ``false``
  67. .. rst-class:: classref-property-setget
  68. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  69. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis **)** |const|
  70. Lock the body's rotation in the X axis.
  71. .. rst-class:: classref-item-separator
  72. ----
  73. .. _class_PhysicsBody3D_property_axis_lock_angular_y:
  74. .. rst-class:: classref-property
  75. :ref:`bool<class_bool>` **axis_lock_angular_y** = ``false``
  76. .. rst-class:: classref-property-setget
  77. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  78. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis **)** |const|
  79. Lock the body's rotation in the Y axis.
  80. .. rst-class:: classref-item-separator
  81. ----
  82. .. _class_PhysicsBody3D_property_axis_lock_angular_z:
  83. .. rst-class:: classref-property
  84. :ref:`bool<class_bool>` **axis_lock_angular_z** = ``false``
  85. .. rst-class:: classref-property-setget
  86. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  87. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis **)** |const|
  88. Lock the body's rotation in the Z axis.
  89. .. rst-class:: classref-item-separator
  90. ----
  91. .. _class_PhysicsBody3D_property_axis_lock_linear_x:
  92. .. rst-class:: classref-property
  93. :ref:`bool<class_bool>` **axis_lock_linear_x** = ``false``
  94. .. rst-class:: classref-property-setget
  95. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  96. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis **)** |const|
  97. Lock the body's linear movement in the X axis.
  98. .. rst-class:: classref-item-separator
  99. ----
  100. .. _class_PhysicsBody3D_property_axis_lock_linear_y:
  101. .. rst-class:: classref-property
  102. :ref:`bool<class_bool>` **axis_lock_linear_y** = ``false``
  103. .. rst-class:: classref-property-setget
  104. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  105. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis **)** |const|
  106. Lock the body's linear movement in the Y axis.
  107. .. rst-class:: classref-item-separator
  108. ----
  109. .. _class_PhysicsBody3D_property_axis_lock_linear_z:
  110. .. rst-class:: classref-property
  111. :ref:`bool<class_bool>` **axis_lock_linear_z** = ``false``
  112. .. rst-class:: classref-property-setget
  113. - void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  114. - :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis **)** |const|
  115. Lock the body's linear movement in the Z axis.
  116. .. rst-class:: classref-section-separator
  117. ----
  118. .. rst-class:: classref-descriptions-group
  119. Method Descriptions
  120. -------------------
  121. .. _class_PhysicsBody3D_method_add_collision_exception_with:
  122. .. rst-class:: classref-method
  123. void **add_collision_exception_with** **(** :ref:`Node<class_Node>` body **)**
  124. Adds a body to the list of bodies that this body can't collide with.
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_PhysicsBody3D_method_get_axis_lock:
  128. .. rst-class:: classref-method
  129. :ref:`bool<class_bool>` **get_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis **)** |const|
  130. Returns ``true`` if the specified linear or rotational ``axis`` is locked.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_PhysicsBody3D_method_get_collision_exceptions:
  134. .. rst-class:: classref-method
  135. :ref:`PhysicsBody3D[]<class_PhysicsBody3D>` **get_collision_exceptions** **(** **)**
  136. Returns an array of nodes that were added as collision exceptions for this body.
  137. .. rst-class:: classref-item-separator
  138. ----
  139. .. _class_PhysicsBody3D_method_move_and_collide:
  140. .. rst-class:: classref-method
  141. :ref:`KinematicCollision3D<class_KinematicCollision3D>` **move_and_collide** **(** :ref:`Vector3<class_Vector3>` motion, :ref:`bool<class_bool>` test_only=false, :ref:`float<class_float>` safe_margin=0.001, :ref:`bool<class_bool>` recovery_as_collision=false, :ref:`int<class_int>` max_collisions=1 **)**
  142. Moves the body along the vector ``motion``. In order to be frame rate independent in :ref:`Node._physics_process<class_Node_private_method__physics_process>` or :ref:`Node._process<class_Node_private_method__process>`, ``motion`` should be computed using ``delta``.
  143. The body will stop if it collides. Returns a :ref:`KinematicCollision3D<class_KinematicCollision3D>`, which contains information about the collision when stopped, or when touching another body along the motion.
  144. If ``test_only`` is ``true``, the body does not move but the would-be collision information is given.
  145. \ ``safe_margin`` is the extra margin used for collision recovery (see :ref:`CharacterBody3D.safe_margin<class_CharacterBody3D_property_safe_margin>` for more details).
  146. If ``recovery_as_collision`` is ``true``, any depenetration from the recovery phase is also reported as a collision; this is used e.g. by :ref:`CharacterBody3D<class_CharacterBody3D>` for improving floor detection during floor snapping.
  147. \ ``max_collisions`` allows to retrieve more than one collision result.
  148. .. rst-class:: classref-item-separator
  149. ----
  150. .. _class_PhysicsBody3D_method_remove_collision_exception_with:
  151. .. rst-class:: classref-method
  152. void **remove_collision_exception_with** **(** :ref:`Node<class_Node>` body **)**
  153. Removes a body from the list of bodies that this body can't collide with.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_PhysicsBody3D_method_set_axis_lock:
  157. .. rst-class:: classref-method
  158. void **set_axis_lock** **(** :ref:`BodyAxis<enum_PhysicsServer3D_BodyAxis>` axis, :ref:`bool<class_bool>` lock **)**
  159. Locks or unlocks the specified linear or rotational ``axis`` depending on the value of ``lock``.
  160. .. rst-class:: classref-item-separator
  161. ----
  162. .. _class_PhysicsBody3D_method_test_move:
  163. .. rst-class:: classref-method
  164. :ref:`bool<class_bool>` **test_move** **(** :ref:`Transform3D<class_Transform3D>` from, :ref:`Vector3<class_Vector3>` motion, :ref:`KinematicCollision3D<class_KinematicCollision3D>` collision=null, :ref:`float<class_float>` safe_margin=0.001, :ref:`bool<class_bool>` recovery_as_collision=false, :ref:`int<class_int>` max_collisions=1 **)**
  165. Checks for collisions without moving the body. In order to be frame rate independent in :ref:`Node._physics_process<class_Node_private_method__physics_process>` or :ref:`Node._process<class_Node_private_method__process>`, ``motion`` should be computed using ``delta``.
  166. Virtually sets the node's position, scale and rotation to that of the given :ref:`Transform3D<class_Transform3D>`, then tries to move the body along the vector ``motion``. Returns ``true`` if a collision would stop the body from moving along the whole path.
  167. \ ``collision`` is an optional object of type :ref:`KinematicCollision3D<class_KinematicCollision3D>`, which contains additional information about the collision when stopped, or when touching another body along the motion.
  168. \ ``safe_margin`` is the extra margin used for collision recovery (see :ref:`CharacterBody3D.safe_margin<class_CharacterBody3D_property_safe_margin>` for more details).
  169. If ``recovery_as_collision`` is ``true``, any depenetration from the recovery phase is also reported as a collision; this is useful for checking whether the body would *touch* any other bodies.
  170. \ ``max_collisions`` allows to retrieve more than one collision result.
  171. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  172. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  173. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  174. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  175. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  176. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  177. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`