class_characterbody3d.rst 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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/CharacterBody3D.xml.
  6. .. _class_CharacterBody3D:
  7. CharacterBody3D
  8. ===============
  9. **Inherits:** :ref:`PhysicsBody3D<class_PhysicsBody3D>` **<** :ref:`CollisionObject3D<class_CollisionObject3D>` **<** :ref:`Node3D<class_Node3D>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. A 3D physics body specialized for characters moved by script.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **CharacterBody3D** is a specialized class for physics bodies that are meant to be user-controlled. They are not affected by physics at all, but they affect other physics bodies in their path. They are mainly used to provide high-level API to move objects with wall and slope detection (:ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>` method) in addition to the general collision detection provided by :ref:`PhysicsBody3D.move_and_collide()<class_PhysicsBody3D_method_move_and_collide>`. This makes it useful for highly configurable physics bodies that must move in specific ways and collide with the world, as is often the case with user-controlled characters.
  15. For game objects that don't require complex movement or collision detection, such as moving platforms, :ref:`AnimatableBody3D<class_AnimatableBody3D>` is simpler to configure.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Physics introduction <../tutorials/physics/physics_introduction>`
  20. - :doc:`Troubleshooting physics issues <../tutorials/physics/troubleshooting_physics_issues>`
  21. - :doc:`Kinematic character (2D) <../tutorials/physics/kinematic_character_2d>`
  22. - `3D Kinematic Character Demo <https://godotengine.org/asset-library/asset/2739>`__
  23. - `3D Platformer Demo <https://godotengine.org/asset-library/asset/2748>`__
  24. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/2755>`__
  25. - `Third Person Shooter (TPS) Demo <https://godotengine.org/asset-library/asset/2710>`__
  26. .. rst-class:: classref-reftable-group
  27. Properties
  28. ----------
  29. .. table::
  30. :widths: auto
  31. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  32. | :ref:`bool<class_bool>` | :ref:`floor_block_on_wall<class_CharacterBody3D_property_floor_block_on_wall>` | ``true`` |
  33. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  34. | :ref:`bool<class_bool>` | :ref:`floor_constant_speed<class_CharacterBody3D_property_floor_constant_speed>` | ``false`` |
  35. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  36. | :ref:`float<class_float>` | :ref:`floor_max_angle<class_CharacterBody3D_property_floor_max_angle>` | ``0.7853982`` |
  37. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  38. | :ref:`float<class_float>` | :ref:`floor_snap_length<class_CharacterBody3D_property_floor_snap_length>` | ``0.1`` |
  39. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  40. | :ref:`bool<class_bool>` | :ref:`floor_stop_on_slope<class_CharacterBody3D_property_floor_stop_on_slope>` | ``true`` |
  41. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  42. | :ref:`int<class_int>` | :ref:`max_slides<class_CharacterBody3D_property_max_slides>` | ``6`` |
  43. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  44. | :ref:`MotionMode<enum_CharacterBody3D_MotionMode>` | :ref:`motion_mode<class_CharacterBody3D_property_motion_mode>` | ``0`` |
  45. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  46. | :ref:`int<class_int>` | :ref:`platform_floor_layers<class_CharacterBody3D_property_platform_floor_layers>` | ``4294967295`` |
  47. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  48. | :ref:`PlatformOnLeave<enum_CharacterBody3D_PlatformOnLeave>` | :ref:`platform_on_leave<class_CharacterBody3D_property_platform_on_leave>` | ``0`` |
  49. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  50. | :ref:`int<class_int>` | :ref:`platform_wall_layers<class_CharacterBody3D_property_platform_wall_layers>` | ``0`` |
  51. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  52. | :ref:`float<class_float>` | :ref:`safe_margin<class_CharacterBody3D_property_safe_margin>` | ``0.001`` |
  53. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  54. | :ref:`bool<class_bool>` | :ref:`slide_on_ceiling<class_CharacterBody3D_property_slide_on_ceiling>` | ``true`` |
  55. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  56. | :ref:`Vector3<class_Vector3>` | :ref:`up_direction<class_CharacterBody3D_property_up_direction>` | ``Vector3(0, 1, 0)`` |
  57. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  58. | :ref:`Vector3<class_Vector3>` | :ref:`velocity<class_CharacterBody3D_property_velocity>` | ``Vector3(0, 0, 0)`` |
  59. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  60. | :ref:`float<class_float>` | :ref:`wall_min_slide_angle<class_CharacterBody3D_property_wall_min_slide_angle>` | ``0.2617994`` |
  61. +--------------------------------------------------------------+------------------------------------------------------------------------------------+----------------------+
  62. .. rst-class:: classref-reftable-group
  63. Methods
  64. -------
  65. .. table::
  66. :widths: auto
  67. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | |void| | :ref:`apply_floor_snap<class_CharacterBody3D_method_apply_floor_snap>`\ (\ ) |
  69. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`float<class_float>` | :ref:`get_floor_angle<class_CharacterBody3D_method_get_floor_angle>`\ (\ up_direction\: :ref:`Vector3<class_Vector3>` = Vector3(0, 1, 0)\ ) |const| |
  71. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`Vector3<class_Vector3>` | :ref:`get_floor_normal<class_CharacterBody3D_method_get_floor_normal>`\ (\ ) |const| |
  73. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Vector3<class_Vector3>` | :ref:`get_last_motion<class_CharacterBody3D_method_get_last_motion>`\ (\ ) |const| |
  75. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`KinematicCollision3D<class_KinematicCollision3D>` | :ref:`get_last_slide_collision<class_CharacterBody3D_method_get_last_slide_collision>`\ (\ ) |
  77. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Vector3<class_Vector3>` | :ref:`get_platform_angular_velocity<class_CharacterBody3D_method_get_platform_angular_velocity>`\ (\ ) |const| |
  79. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Vector3<class_Vector3>` | :ref:`get_platform_velocity<class_CharacterBody3D_method_get_platform_velocity>`\ (\ ) |const| |
  81. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`Vector3<class_Vector3>` | :ref:`get_position_delta<class_CharacterBody3D_method_get_position_delta>`\ (\ ) |const| |
  83. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`Vector3<class_Vector3>` | :ref:`get_real_velocity<class_CharacterBody3D_method_get_real_velocity>`\ (\ ) |const| |
  85. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`KinematicCollision3D<class_KinematicCollision3D>` | :ref:`get_slide_collision<class_CharacterBody3D_method_get_slide_collision>`\ (\ slide_idx\: :ref:`int<class_int>`\ ) |
  87. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`int<class_int>` | :ref:`get_slide_collision_count<class_CharacterBody3D_method_get_slide_collision_count>`\ (\ ) |const| |
  89. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Vector3<class_Vector3>` | :ref:`get_wall_normal<class_CharacterBody3D_method_get_wall_normal>`\ (\ ) |const| |
  91. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`bool<class_bool>` | :ref:`is_on_ceiling<class_CharacterBody3D_method_is_on_ceiling>`\ (\ ) |const| |
  93. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`bool<class_bool>` | :ref:`is_on_ceiling_only<class_CharacterBody3D_method_is_on_ceiling_only>`\ (\ ) |const| |
  95. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`bool<class_bool>` | :ref:`is_on_floor<class_CharacterBody3D_method_is_on_floor>`\ (\ ) |const| |
  97. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`bool<class_bool>` | :ref:`is_on_floor_only<class_CharacterBody3D_method_is_on_floor_only>`\ (\ ) |const| |
  99. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`bool<class_bool>` | :ref:`is_on_wall<class_CharacterBody3D_method_is_on_wall>`\ (\ ) |const| |
  101. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`bool<class_bool>` | :ref:`is_on_wall_only<class_CharacterBody3D_method_is_on_wall_only>`\ (\ ) |const| |
  103. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`bool<class_bool>` | :ref:`move_and_slide<class_CharacterBody3D_method_move_and_slide>`\ (\ ) |
  105. +---------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------+
  106. .. rst-class:: classref-section-separator
  107. ----
  108. .. rst-class:: classref-descriptions-group
  109. Enumerations
  110. ------------
  111. .. _enum_CharacterBody3D_MotionMode:
  112. .. rst-class:: classref-enumeration
  113. enum **MotionMode**: :ref:`🔗<enum_CharacterBody3D_MotionMode>`
  114. .. _class_CharacterBody3D_constant_MOTION_MODE_GROUNDED:
  115. .. rst-class:: classref-enumeration-constant
  116. :ref:`MotionMode<enum_CharacterBody3D_MotionMode>` **MOTION_MODE_GROUNDED** = ``0``
  117. Apply when notions of walls, ceiling and floor are relevant. In this mode the body motion will react to slopes (acceleration/slowdown). This mode is suitable for grounded games like platformers.
  118. .. _class_CharacterBody3D_constant_MOTION_MODE_FLOATING:
  119. .. rst-class:: classref-enumeration-constant
  120. :ref:`MotionMode<enum_CharacterBody3D_MotionMode>` **MOTION_MODE_FLOATING** = ``1``
  121. Apply when there is no notion of floor or ceiling. All collisions will be reported as ``on_wall``. In this mode, when you slide, the speed will always be constant. This mode is suitable for games without ground like space games.
  122. .. rst-class:: classref-item-separator
  123. ----
  124. .. _enum_CharacterBody3D_PlatformOnLeave:
  125. .. rst-class:: classref-enumeration
  126. enum **PlatformOnLeave**: :ref:`🔗<enum_CharacterBody3D_PlatformOnLeave>`
  127. .. _class_CharacterBody3D_constant_PLATFORM_ON_LEAVE_ADD_VELOCITY:
  128. .. rst-class:: classref-enumeration-constant
  129. :ref:`PlatformOnLeave<enum_CharacterBody3D_PlatformOnLeave>` **PLATFORM_ON_LEAVE_ADD_VELOCITY** = ``0``
  130. Add the last platform velocity to the :ref:`velocity<class_CharacterBody3D_property_velocity>` when you leave a moving platform.
  131. .. _class_CharacterBody3D_constant_PLATFORM_ON_LEAVE_ADD_UPWARD_VELOCITY:
  132. .. rst-class:: classref-enumeration-constant
  133. :ref:`PlatformOnLeave<enum_CharacterBody3D_PlatformOnLeave>` **PLATFORM_ON_LEAVE_ADD_UPWARD_VELOCITY** = ``1``
  134. Add the last platform velocity to the :ref:`velocity<class_CharacterBody3D_property_velocity>` when you leave a moving platform, but any downward motion is ignored. It's useful to keep full jump height even when the platform is moving down.
  135. .. _class_CharacterBody3D_constant_PLATFORM_ON_LEAVE_DO_NOTHING:
  136. .. rst-class:: classref-enumeration-constant
  137. :ref:`PlatformOnLeave<enum_CharacterBody3D_PlatformOnLeave>` **PLATFORM_ON_LEAVE_DO_NOTHING** = ``2``
  138. Do nothing when leaving a platform.
  139. .. rst-class:: classref-section-separator
  140. ----
  141. .. rst-class:: classref-descriptions-group
  142. Property Descriptions
  143. ---------------------
  144. .. _class_CharacterBody3D_property_floor_block_on_wall:
  145. .. rst-class:: classref-property
  146. :ref:`bool<class_bool>` **floor_block_on_wall** = ``true`` :ref:`🔗<class_CharacterBody3D_property_floor_block_on_wall>`
  147. .. rst-class:: classref-property-setget
  148. - |void| **set_floor_block_on_wall_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  149. - :ref:`bool<class_bool>` **is_floor_block_on_wall_enabled**\ (\ )
  150. If ``true``, the body will be able to move on the floor only. This option avoids to be able to walk on walls, it will however allow to slide down along them.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_CharacterBody3D_property_floor_constant_speed:
  154. .. rst-class:: classref-property
  155. :ref:`bool<class_bool>` **floor_constant_speed** = ``false`` :ref:`🔗<class_CharacterBody3D_property_floor_constant_speed>`
  156. .. rst-class:: classref-property-setget
  157. - |void| **set_floor_constant_speed_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  158. - :ref:`bool<class_bool>` **is_floor_constant_speed_enabled**\ (\ )
  159. If ``false`` (by default), the body will move faster on downward slopes and slower on upward slopes.
  160. If ``true``, the body will always move at the same speed on the ground no matter the slope. Note that you need to use :ref:`floor_snap_length<class_CharacterBody3D_property_floor_snap_length>` to stick along a downward slope at constant speed.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_CharacterBody3D_property_floor_max_angle:
  164. .. rst-class:: classref-property
  165. :ref:`float<class_float>` **floor_max_angle** = ``0.7853982`` :ref:`🔗<class_CharacterBody3D_property_floor_max_angle>`
  166. .. rst-class:: classref-property-setget
  167. - |void| **set_floor_max_angle**\ (\ value\: :ref:`float<class_float>`\ )
  168. - :ref:`float<class_float>` **get_floor_max_angle**\ (\ )
  169. Maximum angle (in radians) where a slope is still considered a floor (or a ceiling), rather than a wall, when calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. The default value equals 45 degrees.
  170. .. rst-class:: classref-item-separator
  171. ----
  172. .. _class_CharacterBody3D_property_floor_snap_length:
  173. .. rst-class:: classref-property
  174. :ref:`float<class_float>` **floor_snap_length** = ``0.1`` :ref:`🔗<class_CharacterBody3D_property_floor_snap_length>`
  175. .. rst-class:: classref-property-setget
  176. - |void| **set_floor_snap_length**\ (\ value\: :ref:`float<class_float>`\ )
  177. - :ref:`float<class_float>` **get_floor_snap_length**\ (\ )
  178. Sets a snapping distance. When set to a value different from ``0.0``, the body is kept attached to slopes when calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. The snapping vector is determined by the given distance along the opposite direction of the :ref:`up_direction<class_CharacterBody3D_property_up_direction>`.
  179. As long as the snapping vector is in contact with the ground and the body moves against :ref:`up_direction<class_CharacterBody3D_property_up_direction>`, the body will remain attached to the surface. Snapping is not applied if the body moves along :ref:`up_direction<class_CharacterBody3D_property_up_direction>`, meaning it contains vertical rising velocity, so it will be able to detach from the ground when jumping or when the body is pushed up by something. If you want to apply a snap without taking into account the velocity, use :ref:`apply_floor_snap()<class_CharacterBody3D_method_apply_floor_snap>`.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_CharacterBody3D_property_floor_stop_on_slope:
  183. .. rst-class:: classref-property
  184. :ref:`bool<class_bool>` **floor_stop_on_slope** = ``true`` :ref:`🔗<class_CharacterBody3D_property_floor_stop_on_slope>`
  185. .. rst-class:: classref-property-setget
  186. - |void| **set_floor_stop_on_slope_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  187. - :ref:`bool<class_bool>` **is_floor_stop_on_slope_enabled**\ (\ )
  188. If ``true``, the body will not slide on slopes when calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>` when the body is standing still.
  189. If ``false``, the body will slide on floor's slopes when :ref:`velocity<class_CharacterBody3D_property_velocity>` applies a downward force.
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. _class_CharacterBody3D_property_max_slides:
  193. .. rst-class:: classref-property
  194. :ref:`int<class_int>` **max_slides** = ``6`` :ref:`🔗<class_CharacterBody3D_property_max_slides>`
  195. .. rst-class:: classref-property-setget
  196. - |void| **set_max_slides**\ (\ value\: :ref:`int<class_int>`\ )
  197. - :ref:`int<class_int>` **get_max_slides**\ (\ )
  198. Maximum number of times the body can change direction before it stops when calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Must be greater than zero.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. _class_CharacterBody3D_property_motion_mode:
  202. .. rst-class:: classref-property
  203. :ref:`MotionMode<enum_CharacterBody3D_MotionMode>` **motion_mode** = ``0`` :ref:`🔗<class_CharacterBody3D_property_motion_mode>`
  204. .. rst-class:: classref-property-setget
  205. - |void| **set_motion_mode**\ (\ value\: :ref:`MotionMode<enum_CharacterBody3D_MotionMode>`\ )
  206. - :ref:`MotionMode<enum_CharacterBody3D_MotionMode>` **get_motion_mode**\ (\ )
  207. Sets the motion mode which defines the behavior of :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`.
  208. .. rst-class:: classref-item-separator
  209. ----
  210. .. _class_CharacterBody3D_property_platform_floor_layers:
  211. .. rst-class:: classref-property
  212. :ref:`int<class_int>` **platform_floor_layers** = ``4294967295`` :ref:`🔗<class_CharacterBody3D_property_platform_floor_layers>`
  213. .. rst-class:: classref-property-setget
  214. - |void| **set_platform_floor_layers**\ (\ value\: :ref:`int<class_int>`\ )
  215. - :ref:`int<class_int>` **get_platform_floor_layers**\ (\ )
  216. Collision layers that will be included for detecting floor bodies that will act as moving platforms to be followed by the **CharacterBody3D**. By default, all floor bodies are detected and propagate their velocity.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_CharacterBody3D_property_platform_on_leave:
  220. .. rst-class:: classref-property
  221. :ref:`PlatformOnLeave<enum_CharacterBody3D_PlatformOnLeave>` **platform_on_leave** = ``0`` :ref:`🔗<class_CharacterBody3D_property_platform_on_leave>`
  222. .. rst-class:: classref-property-setget
  223. - |void| **set_platform_on_leave**\ (\ value\: :ref:`PlatformOnLeave<enum_CharacterBody3D_PlatformOnLeave>`\ )
  224. - :ref:`PlatformOnLeave<enum_CharacterBody3D_PlatformOnLeave>` **get_platform_on_leave**\ (\ )
  225. Sets the behavior to apply when you leave a moving platform. By default, to be physically accurate, when you leave the last platform velocity is applied.
  226. .. rst-class:: classref-item-separator
  227. ----
  228. .. _class_CharacterBody3D_property_platform_wall_layers:
  229. .. rst-class:: classref-property
  230. :ref:`int<class_int>` **platform_wall_layers** = ``0`` :ref:`🔗<class_CharacterBody3D_property_platform_wall_layers>`
  231. .. rst-class:: classref-property-setget
  232. - |void| **set_platform_wall_layers**\ (\ value\: :ref:`int<class_int>`\ )
  233. - :ref:`int<class_int>` **get_platform_wall_layers**\ (\ )
  234. Collision layers that will be included for detecting wall bodies that will act as moving platforms to be followed by the **CharacterBody3D**. By default, all wall bodies are ignored.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_CharacterBody3D_property_safe_margin:
  238. .. rst-class:: classref-property
  239. :ref:`float<class_float>` **safe_margin** = ``0.001`` :ref:`🔗<class_CharacterBody3D_property_safe_margin>`
  240. .. rst-class:: classref-property-setget
  241. - |void| **set_safe_margin**\ (\ value\: :ref:`float<class_float>`\ )
  242. - :ref:`float<class_float>` **get_safe_margin**\ (\ )
  243. Extra margin used for collision recovery when calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`.
  244. If the body is at least this close to another body, it will consider them to be colliding and will be pushed away before performing the actual motion.
  245. A higher value means it's more flexible for detecting collision, which helps with consistently detecting walls and floors.
  246. A lower value forces the collision algorithm to use more exact detection, so it can be used in cases that specifically require precision, e.g at very low scale to avoid visible jittering, or for stability with a stack of character bodies.
  247. .. rst-class:: classref-item-separator
  248. ----
  249. .. _class_CharacterBody3D_property_slide_on_ceiling:
  250. .. rst-class:: classref-property
  251. :ref:`bool<class_bool>` **slide_on_ceiling** = ``true`` :ref:`🔗<class_CharacterBody3D_property_slide_on_ceiling>`
  252. .. rst-class:: classref-property-setget
  253. - |void| **set_slide_on_ceiling_enabled**\ (\ value\: :ref:`bool<class_bool>`\ )
  254. - :ref:`bool<class_bool>` **is_slide_on_ceiling_enabled**\ (\ )
  255. If ``true``, during a jump against the ceiling, the body will slide, if ``false`` it will be stopped and will fall vertically.
  256. .. rst-class:: classref-item-separator
  257. ----
  258. .. _class_CharacterBody3D_property_up_direction:
  259. .. rst-class:: classref-property
  260. :ref:`Vector3<class_Vector3>` **up_direction** = ``Vector3(0, 1, 0)`` :ref:`🔗<class_CharacterBody3D_property_up_direction>`
  261. .. rst-class:: classref-property-setget
  262. - |void| **set_up_direction**\ (\ value\: :ref:`Vector3<class_Vector3>`\ )
  263. - :ref:`Vector3<class_Vector3>` **get_up_direction**\ (\ )
  264. Vector pointing upwards, used to determine what is a wall and what is a floor (or a ceiling) when calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Defaults to :ref:`Vector3.UP<class_Vector3_constant_UP>`. As the vector will be normalized it can't be equal to :ref:`Vector3.ZERO<class_Vector3_constant_ZERO>`, if you want all collisions to be reported as walls, consider using :ref:`MOTION_MODE_FLOATING<class_CharacterBody3D_constant_MOTION_MODE_FLOATING>` as :ref:`motion_mode<class_CharacterBody3D_property_motion_mode>`.
  265. .. rst-class:: classref-item-separator
  266. ----
  267. .. _class_CharacterBody3D_property_velocity:
  268. .. rst-class:: classref-property
  269. :ref:`Vector3<class_Vector3>` **velocity** = ``Vector3(0, 0, 0)`` :ref:`🔗<class_CharacterBody3D_property_velocity>`
  270. .. rst-class:: classref-property-setget
  271. - |void| **set_velocity**\ (\ value\: :ref:`Vector3<class_Vector3>`\ )
  272. - :ref:`Vector3<class_Vector3>` **get_velocity**\ (\ )
  273. Current velocity vector (typically meters per second), used and modified during calls to :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`.
  274. \ **Note:** A common mistake is setting this property to the desired velocity multiplied by ``delta``, which produces a motion vector (typically in meters).
  275. .. rst-class:: classref-item-separator
  276. ----
  277. .. _class_CharacterBody3D_property_wall_min_slide_angle:
  278. .. rst-class:: classref-property
  279. :ref:`float<class_float>` **wall_min_slide_angle** = ``0.2617994`` :ref:`🔗<class_CharacterBody3D_property_wall_min_slide_angle>`
  280. .. rst-class:: classref-property-setget
  281. - |void| **set_wall_min_slide_angle**\ (\ value\: :ref:`float<class_float>`\ )
  282. - :ref:`float<class_float>` **get_wall_min_slide_angle**\ (\ )
  283. Minimum angle (in radians) where the body is allowed to slide when it encounters a wall. The default value equals 15 degrees. When :ref:`motion_mode<class_CharacterBody3D_property_motion_mode>` is :ref:`MOTION_MODE_GROUNDED<class_CharacterBody3D_constant_MOTION_MODE_GROUNDED>`, it only affects movement if :ref:`floor_block_on_wall<class_CharacterBody3D_property_floor_block_on_wall>` is ``true``.
  284. .. rst-class:: classref-section-separator
  285. ----
  286. .. rst-class:: classref-descriptions-group
  287. Method Descriptions
  288. -------------------
  289. .. _class_CharacterBody3D_method_apply_floor_snap:
  290. .. rst-class:: classref-method
  291. |void| **apply_floor_snap**\ (\ ) :ref:`🔗<class_CharacterBody3D_method_apply_floor_snap>`
  292. Allows to manually apply a snap to the floor regardless of the body's velocity. This function does nothing when :ref:`is_on_floor()<class_CharacterBody3D_method_is_on_floor>` returns ``true``.
  293. .. rst-class:: classref-item-separator
  294. ----
  295. .. _class_CharacterBody3D_method_get_floor_angle:
  296. .. rst-class:: classref-method
  297. :ref:`float<class_float>` **get_floor_angle**\ (\ up_direction\: :ref:`Vector3<class_Vector3>` = Vector3(0, 1, 0)\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_floor_angle>`
  298. Returns the floor's collision angle at the last collision point according to ``up_direction``, which is :ref:`Vector3.UP<class_Vector3_constant_UP>` by default. This value is always positive and only valid after calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>` and when :ref:`is_on_floor()<class_CharacterBody3D_method_is_on_floor>` returns ``true``.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_CharacterBody3D_method_get_floor_normal:
  302. .. rst-class:: classref-method
  303. :ref:`Vector3<class_Vector3>` **get_floor_normal**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_floor_normal>`
  304. Returns the collision normal of the floor at the last collision point. Only valid after calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>` and when :ref:`is_on_floor()<class_CharacterBody3D_method_is_on_floor>` returns ``true``.
  305. \ **Warning:** The collision normal is not always the same as the surface normal.
  306. .. rst-class:: classref-item-separator
  307. ----
  308. .. _class_CharacterBody3D_method_get_last_motion:
  309. .. rst-class:: classref-method
  310. :ref:`Vector3<class_Vector3>` **get_last_motion**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_last_motion>`
  311. Returns the last motion applied to the **CharacterBody3D** during the last call to :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. The movement can be split into multiple motions when sliding occurs, and this method return the last one, which is useful to retrieve the current direction of the movement.
  312. .. rst-class:: classref-item-separator
  313. ----
  314. .. _class_CharacterBody3D_method_get_last_slide_collision:
  315. .. rst-class:: classref-method
  316. :ref:`KinematicCollision3D<class_KinematicCollision3D>` **get_last_slide_collision**\ (\ ) :ref:`🔗<class_CharacterBody3D_method_get_last_slide_collision>`
  317. Returns a :ref:`KinematicCollision3D<class_KinematicCollision3D>`, which contains information about the latest collision that occurred during the last call to :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`.
  318. .. rst-class:: classref-item-separator
  319. ----
  320. .. _class_CharacterBody3D_method_get_platform_angular_velocity:
  321. .. rst-class:: classref-method
  322. :ref:`Vector3<class_Vector3>` **get_platform_angular_velocity**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_platform_angular_velocity>`
  323. Returns the angular velocity of the platform at the last collision point. Only valid after calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`.
  324. .. rst-class:: classref-item-separator
  325. ----
  326. .. _class_CharacterBody3D_method_get_platform_velocity:
  327. .. rst-class:: classref-method
  328. :ref:`Vector3<class_Vector3>` **get_platform_velocity**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_platform_velocity>`
  329. Returns the linear velocity of the platform at the last collision point. Only valid after calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`.
  330. .. rst-class:: classref-item-separator
  331. ----
  332. .. _class_CharacterBody3D_method_get_position_delta:
  333. .. rst-class:: classref-method
  334. :ref:`Vector3<class_Vector3>` **get_position_delta**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_position_delta>`
  335. Returns the travel (position delta) that occurred during the last call to :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`.
  336. .. rst-class:: classref-item-separator
  337. ----
  338. .. _class_CharacterBody3D_method_get_real_velocity:
  339. .. rst-class:: classref-method
  340. :ref:`Vector3<class_Vector3>` **get_real_velocity**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_real_velocity>`
  341. Returns the current real velocity since the last call to :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. For example, when you climb a slope, you will move diagonally even though the velocity is horizontal. This method returns the diagonal movement, as opposed to :ref:`velocity<class_CharacterBody3D_property_velocity>` which returns the requested velocity.
  342. .. rst-class:: classref-item-separator
  343. ----
  344. .. _class_CharacterBody3D_method_get_slide_collision:
  345. .. rst-class:: classref-method
  346. :ref:`KinematicCollision3D<class_KinematicCollision3D>` **get_slide_collision**\ (\ slide_idx\: :ref:`int<class_int>`\ ) :ref:`🔗<class_CharacterBody3D_method_get_slide_collision>`
  347. Returns a :ref:`KinematicCollision3D<class_KinematicCollision3D>`, which contains information about a collision that occurred during the last call to :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Since the body can collide several times in a single call to :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`, you must specify the index of the collision in the range 0 to (:ref:`get_slide_collision_count()<class_CharacterBody3D_method_get_slide_collision_count>` - 1).
  348. .. rst-class:: classref-item-separator
  349. ----
  350. .. _class_CharacterBody3D_method_get_slide_collision_count:
  351. .. rst-class:: classref-method
  352. :ref:`int<class_int>` **get_slide_collision_count**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_slide_collision_count>`
  353. Returns the number of times the body collided and changed direction during the last call to :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`.
  354. .. rst-class:: classref-item-separator
  355. ----
  356. .. _class_CharacterBody3D_method_get_wall_normal:
  357. .. rst-class:: classref-method
  358. :ref:`Vector3<class_Vector3>` **get_wall_normal**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_get_wall_normal>`
  359. Returns the collision normal of the wall at the last collision point. Only valid after calling :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>` and when :ref:`is_on_wall()<class_CharacterBody3D_method_is_on_wall>` returns ``true``.
  360. \ **Warning:** The collision normal is not always the same as the surface normal.
  361. .. rst-class:: classref-item-separator
  362. ----
  363. .. _class_CharacterBody3D_method_is_on_ceiling:
  364. .. rst-class:: classref-method
  365. :ref:`bool<class_bool>` **is_on_ceiling**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_is_on_ceiling>`
  366. Returns ``true`` if the body collided with the ceiling on the last call of :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody3D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody3D_property_floor_max_angle>` are used to determine whether a surface is "ceiling" or not.
  367. .. rst-class:: classref-item-separator
  368. ----
  369. .. _class_CharacterBody3D_method_is_on_ceiling_only:
  370. .. rst-class:: classref-method
  371. :ref:`bool<class_bool>` **is_on_ceiling_only**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_is_on_ceiling_only>`
  372. Returns ``true`` if the body collided only with the ceiling on the last call of :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody3D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody3D_property_floor_max_angle>` are used to determine whether a surface is "ceiling" or not.
  373. .. rst-class:: classref-item-separator
  374. ----
  375. .. _class_CharacterBody3D_method_is_on_floor:
  376. .. rst-class:: classref-method
  377. :ref:`bool<class_bool>` **is_on_floor**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_is_on_floor>`
  378. Returns ``true`` if the body collided with the floor on the last call of :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody3D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody3D_property_floor_max_angle>` are used to determine whether a surface is "floor" or not.
  379. .. rst-class:: classref-item-separator
  380. ----
  381. .. _class_CharacterBody3D_method_is_on_floor_only:
  382. .. rst-class:: classref-method
  383. :ref:`bool<class_bool>` **is_on_floor_only**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_is_on_floor_only>`
  384. Returns ``true`` if the body collided only with the floor on the last call of :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody3D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody3D_property_floor_max_angle>` are used to determine whether a surface is "floor" or not.
  385. .. rst-class:: classref-item-separator
  386. ----
  387. .. _class_CharacterBody3D_method_is_on_wall:
  388. .. rst-class:: classref-method
  389. :ref:`bool<class_bool>` **is_on_wall**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_is_on_wall>`
  390. Returns ``true`` if the body collided with a wall on the last call of :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody3D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody3D_property_floor_max_angle>` are used to determine whether a surface is "wall" or not.
  391. .. rst-class:: classref-item-separator
  392. ----
  393. .. _class_CharacterBody3D_method_is_on_wall_only:
  394. .. rst-class:: classref-method
  395. :ref:`bool<class_bool>` **is_on_wall_only**\ (\ ) |const| :ref:`🔗<class_CharacterBody3D_method_is_on_wall_only>`
  396. Returns ``true`` if the body collided only with a wall on the last call of :ref:`move_and_slide()<class_CharacterBody3D_method_move_and_slide>`. Otherwise, returns ``false``. The :ref:`up_direction<class_CharacterBody3D_property_up_direction>` and :ref:`floor_max_angle<class_CharacterBody3D_property_floor_max_angle>` are used to determine whether a surface is "wall" or not.
  397. .. rst-class:: classref-item-separator
  398. ----
  399. .. _class_CharacterBody3D_method_move_and_slide:
  400. .. rst-class:: classref-method
  401. :ref:`bool<class_bool>` **move_and_slide**\ (\ ) :ref:`🔗<class_CharacterBody3D_method_move_and_slide>`
  402. Moves the body based on :ref:`velocity<class_CharacterBody3D_property_velocity>`. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a **CharacterBody3D** or :ref:`RigidBody3D<class_RigidBody3D>`, it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes.
  403. This method should be used in :ref:`Node._physics_process()<class_Node_private_method__physics_process>` (or in a method called by :ref:`Node._physics_process()<class_Node_private_method__physics_process>`), as it uses the physics step's ``delta`` value automatically in calculations. Otherwise, the simulation will run at an incorrect speed.
  404. Modifies :ref:`velocity<class_CharacterBody3D_property_velocity>` if a slide collision occurred. To get the latest collision call :ref:`get_last_slide_collision()<class_CharacterBody3D_method_get_last_slide_collision>`, for more detailed information about collisions that occurred, use :ref:`get_slide_collision()<class_CharacterBody3D_method_get_slide_collision>`.
  405. When the body touches a moving platform, the platform's velocity is automatically added to the body motion. If a collision occurs due to the platform's motion, it will always be first in the slide collisions.
  406. Returns ``true`` if the body collided, otherwise, returns ``false``.
  407. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  408. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  409. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  410. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  411. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  412. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  413. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  414. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  415. .. |void| replace:: :abbr:`void (No return value.)`