:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/PhysicsBody2D.xml. .. _class_PhysicsBody2D: PhysicsBody2D ============= **Inherits:** :ref:`CollisionObject2D` **<** :ref:`Node2D` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` **Inherited By:** :ref:`CharacterBody2D`, :ref:`RigidBody2D`, :ref:`StaticBody2D` Abstract base class for 2D game objects affected by physics. .. rst-class:: classref-introduction-group Description ----------- **PhysicsBody2D** is an abstract base class for 2D game objects affected by physics. All 2D physics bodies inherit from it. .. rst-class:: classref-introduction-group Tutorials --------- - :doc:`Physics introduction <../tutorials/physics/physics_introduction>` .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +-------------------------+----------------+-------------------------------------------------------------------------------------------------+ | :ref:`bool` | input_pickable | ``false`` (overrides :ref:`CollisionObject2D`) | +-------------------------+----------------+-------------------------------------------------------------------------------------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_collision_exception_with`\ (\ body\: :ref:`Node`\ ) | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array`\[:ref:`PhysicsBody2D`\] | :ref:`get_collision_exceptions`\ (\ ) | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_gravity`\ (\ ) |const| | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`KinematicCollision2D` | :ref:`move_and_collide`\ (\ motion\: :ref:`Vector2`, test_only\: :ref:`bool` = false, safe_margin\: :ref:`float` = 0.08, recovery_as_collision\: :ref:`bool` = false\ ) | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`remove_collision_exception_with`\ (\ body\: :ref:`Node`\ ) | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`test_move`\ (\ from\: :ref:`Transform2D`, motion\: :ref:`Vector2`, collision\: :ref:`KinematicCollision2D` = null, safe_margin\: :ref:`float` = 0.08, recovery_as_collision\: :ref:`bool` = false\ ) | +------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_PhysicsBody2D_method_add_collision_exception_with: .. rst-class:: classref-method |void| **add_collision_exception_with**\ (\ body\: :ref:`Node`\ ) :ref:`🔗` Adds a body to the list of bodies that this body can't collide with. .. rst-class:: classref-item-separator ---- .. _class_PhysicsBody2D_method_get_collision_exceptions: .. rst-class:: classref-method :ref:`Array`\[:ref:`PhysicsBody2D`\] **get_collision_exceptions**\ (\ ) :ref:`🔗` Returns an array of nodes that were added as collision exceptions for this body. .. rst-class:: classref-item-separator ---- .. _class_PhysicsBody2D_method_get_gravity: .. rst-class:: classref-method :ref:`Vector2` **get_gravity**\ (\ ) |const| :ref:`🔗` Returns the gravity vector computed from all sources that can affect the body, including all gravity overrides from :ref:`Area2D` nodes and the global world gravity. .. rst-class:: classref-item-separator ---- .. _class_PhysicsBody2D_method_move_and_collide: .. rst-class:: classref-method :ref:`KinematicCollision2D` **move_and_collide**\ (\ motion\: :ref:`Vector2`, test_only\: :ref:`bool` = false, safe_margin\: :ref:`float` = 0.08, recovery_as_collision\: :ref:`bool` = false\ ) :ref:`🔗` Moves the body along the vector ``motion``. In order to be frame rate independent in :ref:`Node._physics_process()` or :ref:`Node._process()`, ``motion`` should be computed using ``delta``. Returns a :ref:`KinematicCollision2D`, which contains information about the collision when stopped, or when touching another body along the motion. If ``test_only`` is ``true``, the body does not move but the would-be collision information is given. \ ``safe_margin`` is the extra margin used for collision recovery (see :ref:`CharacterBody2D.safe_margin` for more details). 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` for improving floor detection during floor snapping. .. rst-class:: classref-item-separator ---- .. _class_PhysicsBody2D_method_remove_collision_exception_with: .. rst-class:: classref-method |void| **remove_collision_exception_with**\ (\ body\: :ref:`Node`\ ) :ref:`🔗` Removes a body from the list of bodies that this body can't collide with. .. rst-class:: classref-item-separator ---- .. _class_PhysicsBody2D_method_test_move: .. rst-class:: classref-method :ref:`bool` **test_move**\ (\ from\: :ref:`Transform2D`, motion\: :ref:`Vector2`, collision\: :ref:`KinematicCollision2D` = null, safe_margin\: :ref:`float` = 0.08, recovery_as_collision\: :ref:`bool` = false\ ) :ref:`🔗` Checks for collisions without moving the body. In order to be frame rate independent in :ref:`Node._physics_process()` or :ref:`Node._process()`, ``motion`` should be computed using ``delta``. Virtually sets the node's position, scale and rotation to that of the given :ref:`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. \ ``collision`` is an optional object of type :ref:`KinematicCollision2D`, which contains additional information about the collision when stopped, or when touching another body along the motion. \ ``safe_margin`` is the extra margin used for collision recovery (see :ref:`CharacterBody2D.safe_margin` for more details). 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. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)` .. |void| replace:: :abbr:`void (No return value.)`