class_physicsbody2d.rst 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the PhysicsBody2D.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_PhysicsBody2D:
  6. PhysicsBody2D
  7. =============
  8. **Inherits:** :ref:`CollisionObject2D<class_CollisionObject2D>` **<** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`CharacterBody2D<class_CharacterBody2D>`, :ref:`RigidDynamicBody2D<class_RigidDynamicBody2D>`, :ref:`StaticBody2D<class_StaticBody2D>`
  10. Base class for all objects affected by physics in 2D space.
  11. Description
  12. -----------
  13. PhysicsBody2D is an abstract base class for implementing a physics body. All \*Body2D types inherit from it.
  14. Tutorials
  15. ---------
  16. - :doc:`Physics introduction <../tutorials/physics/physics_introduction>`
  17. Properties
  18. ----------
  19. +-------------------------+----------------+-------------------------------------------------------------------------------------------------+
  20. | :ref:`bool<class_bool>` | input_pickable | ``false`` (overrides :ref:`CollisionObject2D<class_CollisionObject2D_property_input_pickable>`) |
  21. +-------------------------+----------------+-------------------------------------------------------------------------------------------------+
  22. Methods
  23. -------
  24. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`add_collision_exception_with<class_PhysicsBody2D_method_add_collision_exception_with>` **(** :ref:`Node<class_Node>` body **)** |
  26. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`PhysicsBody2D[]<class_PhysicsBody2D>` | :ref:`get_collision_exceptions<class_PhysicsBody2D_method_get_collision_exceptions>` **(** **)** |
  28. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`KinematicCollision2D<class_KinematicCollision2D>` | :ref:`move_and_collide<class_PhysicsBody2D_method_move_and_collide>` **(** :ref:`Vector2<class_Vector2>` distance, :ref:`bool<class_bool>` test_only=false, :ref:`float<class_float>` safe_margin=0.08 **)** |
  30. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`remove_collision_exception_with<class_PhysicsBody2D_method_remove_collision_exception_with>` **(** :ref:`Node<class_Node>` body **)** |
  32. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`bool<class_bool>` | :ref:`test_move<class_PhysicsBody2D_method_test_move>` **(** :ref:`Transform2D<class_Transform2D>` from, :ref:`Vector2<class_Vector2>` distance, :ref:`KinematicCollision2D<class_KinematicCollision2D>` collision=null, :ref:`float<class_float>` safe_margin=0.08 **)** |
  34. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. Method Descriptions
  36. -------------------
  37. .. _class_PhysicsBody2D_method_add_collision_exception_with:
  38. - void **add_collision_exception_with** **(** :ref:`Node<class_Node>` body **)**
  39. Adds a body to the list of bodies that this body can't collide with.
  40. ----
  41. .. _class_PhysicsBody2D_method_get_collision_exceptions:
  42. - :ref:`PhysicsBody2D[]<class_PhysicsBody2D>` **get_collision_exceptions** **(** **)**
  43. Returns an array of nodes that were added as collision exceptions for this body.
  44. ----
  45. .. _class_PhysicsBody2D_method_move_and_collide:
  46. - :ref:`KinematicCollision2D<class_KinematicCollision2D>` **move_and_collide** **(** :ref:`Vector2<class_Vector2>` distance, :ref:`bool<class_bool>` test_only=false, :ref:`float<class_float>` safe_margin=0.08 **)**
  47. Moves the body along the vector ``distance``. In order to be frame rate independent in :ref:`Node._physics_process<class_Node_method__physics_process>` or :ref:`Node._process<class_Node_method__process>`, ``distance`` should be computed using ``delta``.
  48. Returns a :ref:`KinematicCollision2D<class_KinematicCollision2D>`, which contains information about the collision when stopped, or when touching another body along the motion.
  49. If ``test_only`` is ``true``, the body does not move but the would-be collision information is given.
  50. \ ``safe_margin`` is the extra margin used for collision recovery (see :ref:`CharacterBody2D.collision/safe_margin<class_CharacterBody2D_property_collision/safe_margin>` for more details).
  51. ----
  52. .. _class_PhysicsBody2D_method_remove_collision_exception_with:
  53. - void **remove_collision_exception_with** **(** :ref:`Node<class_Node>` body **)**
  54. Removes a body from the list of bodies that this body can't collide with.
  55. ----
  56. .. _class_PhysicsBody2D_method_test_move:
  57. - :ref:`bool<class_bool>` **test_move** **(** :ref:`Transform2D<class_Transform2D>` from, :ref:`Vector2<class_Vector2>` distance, :ref:`KinematicCollision2D<class_KinematicCollision2D>` collision=null, :ref:`float<class_float>` safe_margin=0.08 **)**
  58. Checks for collisions without moving the body. In order to be frame rate independent in :ref:`Node._physics_process<class_Node_method__physics_process>` or :ref:`Node._process<class_Node_method__process>`, ``distance`` should be computed using ``delta``.
  59. 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 ``distance``. Returns ``true`` if a collision would stop the body from moving along the whole path.
  60. \ ``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.
  61. \ ``safe_margin`` is the extra margin used for collision recovery (see :ref:`CharacterBody2D.collision/safe_margin<class_CharacterBody2D_property_collision/safe_margin>` for more details).
  62. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  63. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  64. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  65. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  66. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  67. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`