class_physicsbody2d.rst 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/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:`RigidDynamicBody2D<class_RigidDynamicBody2D>`, :ref:`StaticBody2D<class_StaticBody2D>`
  11. Base class for all objects affected by physics in 2D space.
  12. Description
  13. -----------
  14. PhysicsBody2D is an abstract base class for implementing a physics body. All \*Body2D types inherit from it.
  15. Tutorials
  16. ---------
  17. - :doc:`Physics introduction <../tutorials/physics/physics_introduction>`
  18. Properties
  19. ----------
  20. +-------------------------+----------------+-------------------------------------------------------------------------------------------------+
  21. | :ref:`bool<class_bool>` | input_pickable | ``false`` (overrides :ref:`CollisionObject2D<class_CollisionObject2D_property_input_pickable>`) |
  22. +-------------------------+----------------+-------------------------------------------------------------------------------------------------+
  23. Methods
  24. -------
  25. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | void | :ref:`add_collision_exception_with<class_PhysicsBody2D_method_add_collision_exception_with>` **(** :ref:`Node<class_Node>` body **)** |
  27. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`PhysicsBody2D[]<class_PhysicsBody2D>` | :ref:`get_collision_exceptions<class_PhysicsBody2D_method_get_collision_exceptions>` **(** **)** |
  29. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :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 **)** |
  31. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | void | :ref:`remove_collision_exception_with<class_PhysicsBody2D_method_remove_collision_exception_with>` **(** :ref:`Node<class_Node>` body **)** |
  33. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :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 **)** |
  35. +---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. Method Descriptions
  37. -------------------
  38. .. _class_PhysicsBody2D_method_add_collision_exception_with:
  39. - void **add_collision_exception_with** **(** :ref:`Node<class_Node>` body **)**
  40. Adds a body to the list of bodies that this body can't collide with.
  41. ----
  42. .. _class_PhysicsBody2D_method_get_collision_exceptions:
  43. - :ref:`PhysicsBody2D[]<class_PhysicsBody2D>` **get_collision_exceptions** **(** **)**
  44. Returns an array of nodes that were added as collision exceptions for this body.
  45. ----
  46. .. _class_PhysicsBody2D_method_move_and_collide:
  47. - :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 **)**
  48. 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``.
  49. Returns a :ref:`KinematicCollision2D<class_KinematicCollision2D>`, which contains information about the collision when stopped, or when touching another body along the motion.
  50. If ``test_only`` is ``true``, the body does not move but the would-be collision information is given.
  51. \ ``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).
  52. ----
  53. .. _class_PhysicsBody2D_method_remove_collision_exception_with:
  54. - void **remove_collision_exception_with** **(** :ref:`Node<class_Node>` body **)**
  55. Removes a body from the list of bodies that this body can't collide with.
  56. ----
  57. .. _class_PhysicsBody2D_method_test_move:
  58. - :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 **)**
  59. 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``.
  60. 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.
  61. \ ``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.
  62. \ ``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).
  63. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  64. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  65. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  66. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  67. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  68. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`