class_physicsbody2d.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/PhysicsBody2D.xml.
  6. .. _class_PhysicsBody2D:
  7. PhysicsBody2D
  8. =============
  9. **Inherits:** :ref:`CollisionObject2D<class_CollisionObject2D>` **<** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`CharacterBody2D<class_CharacterBody2D>`, :ref:`RigidBody2D<class_RigidBody2D>`, :ref:`StaticBody2D<class_StaticBody2D>`
  11. Abstract base class for 2D game objects affected by physics.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. **PhysicsBody2D** is an abstract base class for 2D game objects affected by physics. All 2D physics bodies inherit from it.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Physics introduction <../tutorials/physics/physics_introduction>`
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +-------------------------+----------------+-------------------------------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | input_pickable | ``false`` (overrides :ref:`CollisionObject2D<class_CollisionObject2D_property_input_pickable>`) |
  27. +-------------------------+----------------+-------------------------------------------------------------------------------------------------+
  28. .. rst-class:: classref-reftable-group
  29. Methods
  30. -------
  31. .. table::
  32. :widths: auto
  33. +---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`add_collision_exception_with<class_PhysicsBody2D_method_add_collision_exception_with>` **(** :ref:`Node<class_Node>` body **)** |
  35. +---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`PhysicsBody2D[]<class_PhysicsBody2D>` | :ref:`get_collision_exceptions<class_PhysicsBody2D_method_get_collision_exceptions>` **(** **)** |
  37. +---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`KinematicCollision2D<class_KinematicCollision2D>` | :ref:`move_and_collide<class_PhysicsBody2D_method_move_and_collide>` **(** :ref:`Vector2<class_Vector2>` motion, :ref:`bool<class_bool>` test_only=false, :ref:`float<class_float>` safe_margin=0.08, :ref:`bool<class_bool>` recovery_as_collision=false **)** |
  39. +---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`remove_collision_exception_with<class_PhysicsBody2D_method_remove_collision_exception_with>` **(** :ref:`Node<class_Node>` body **)** |
  41. +---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`bool<class_bool>` | :ref:`test_move<class_PhysicsBody2D_method_test_move>` **(** :ref:`Transform2D<class_Transform2D>` from, :ref:`Vector2<class_Vector2>` motion, :ref:`KinematicCollision2D<class_KinematicCollision2D>` collision=null, :ref:`float<class_float>` safe_margin=0.08, :ref:`bool<class_bool>` recovery_as_collision=false **)** |
  43. +---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. .. rst-class:: classref-section-separator
  45. ----
  46. .. rst-class:: classref-descriptions-group
  47. Method Descriptions
  48. -------------------
  49. .. _class_PhysicsBody2D_method_add_collision_exception_with:
  50. .. rst-class:: classref-method
  51. void **add_collision_exception_with** **(** :ref:`Node<class_Node>` body **)**
  52. Adds a body to the list of bodies that this body can't collide with.
  53. .. rst-class:: classref-item-separator
  54. ----
  55. .. _class_PhysicsBody2D_method_get_collision_exceptions:
  56. .. rst-class:: classref-method
  57. :ref:`PhysicsBody2D[]<class_PhysicsBody2D>` **get_collision_exceptions** **(** **)**
  58. Returns an array of nodes that were added as collision exceptions for this body.
  59. .. rst-class:: classref-item-separator
  60. ----
  61. .. _class_PhysicsBody2D_method_move_and_collide:
  62. .. rst-class:: classref-method
  63. :ref:`KinematicCollision2D<class_KinematicCollision2D>` **move_and_collide** **(** :ref:`Vector2<class_Vector2>` motion, :ref:`bool<class_bool>` test_only=false, :ref:`float<class_float>` safe_margin=0.08, :ref:`bool<class_bool>` recovery_as_collision=false **)**
  64. 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``.
  65. Returns a :ref:`KinematicCollision2D<class_KinematicCollision2D>`, which contains information about the collision when stopped, or when touching another body along the motion.
  66. If ``test_only`` is ``true``, the body does not move but the would-be collision information is given.
  67. \ ``safe_margin`` is the extra margin used for collision recovery (see :ref:`CharacterBody2D.safe_margin<class_CharacterBody2D_property_safe_margin>` for more details).
  68. 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:`CharacterBody2D<class_CharacterBody2D>` for improving floor detection during floor snapping.
  69. .. rst-class:: classref-item-separator
  70. ----
  71. .. _class_PhysicsBody2D_method_remove_collision_exception_with:
  72. .. rst-class:: classref-method
  73. void **remove_collision_exception_with** **(** :ref:`Node<class_Node>` body **)**
  74. Removes a body from the list of bodies that this body can't collide with.
  75. .. rst-class:: classref-item-separator
  76. ----
  77. .. _class_PhysicsBody2D_method_test_move:
  78. .. rst-class:: classref-method
  79. :ref:`bool<class_bool>` **test_move** **(** :ref:`Transform2D<class_Transform2D>` from, :ref:`Vector2<class_Vector2>` motion, :ref:`KinematicCollision2D<class_KinematicCollision2D>` collision=null, :ref:`float<class_float>` safe_margin=0.08, :ref:`bool<class_bool>` recovery_as_collision=false **)**
  80. 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``.
  81. Virtually sets the node's position, scale and rotation to that of the given :ref:`Transform2D<class_Transform2D>`, 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.
  82. \ ``collision`` is an optional object of type :ref:`KinematicCollision2D<class_KinematicCollision2D>`, which contains additional information about the collision when stopped, or when touching another body along the motion.
  83. \ ``safe_margin`` is the extra margin used for collision recovery (see :ref:`CharacterBody2D.safe_margin<class_CharacterBody2D_property_safe_margin>` for more details).
  84. 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.
  85. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  86. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  87. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  88. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  89. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  90. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  91. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`