:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Area2D.xml. .. _class_Area2D: Area2D ====== **Inherits:** :ref:`CollisionObject2D` **<** :ref:`Node2D` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` 2D area for detection and physics and audio influence. .. rst-class:: classref-introduction-group Description ----------- 2D area that detects :ref:`CollisionObject2D` nodes overlapping, entering, or exiting. Can also alter or override local physics parameters (gravity, damping) and route audio to a custom audio bus. To give the area its shape, add a :ref:`CollisionShape2D` or a :ref:`CollisionPolygon2D` node as a *direct* child (or add multiple such nodes as direct children) of the area. \ **Warning:** See :ref:`ConcavePolygonShape2D` for a warning about possibly unexpected behavior when using that shape for an area. .. rst-class:: classref-introduction-group Tutorials --------- - :doc:`Using Area2D <../tutorials/physics/using_area_2d>` - `2D Dodge The Creeps Demo `__ - `2D Pong Demo `__ - `2D Platformer Demo `__ .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`angular_damp` | ``1.0`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`String` | :ref:`audio_bus_name` | ``"Master"`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`audio_bus_override` | ``false`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`gravity` | ``98.0`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`gravity_distance_scale` | ``0.0`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`gravity_point` | ``false`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`gravity_vec` | ``Vector2( 0, 1 )`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`linear_damp` | ``0.1`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`monitorable` | ``true`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`monitoring` | ``true`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`priority` | ``0.0`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ | :ref:`SpaceOverride` | :ref:`space_override` | ``0`` | +-------------------------------------------------+-----------------------------------------------------------------------------+---------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +---------------------------+----------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_overlapping_areas` **(** **)** |const| | +---------------------------+----------------------------------------------------------------------------------------------------------+ | :ref:`Array` | :ref:`get_overlapping_bodies` **(** **)** |const| | +---------------------------+----------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`overlaps_area` **(** :ref:`Node` area **)** |const| | +---------------------------+----------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`overlaps_body` **(** :ref:`Node` body **)** |const| | +---------------------------+----------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Signals ------- .. _class_Area2D_signal_area_entered: .. rst-class:: classref-signal **area_entered** **(** :ref:`Area2D` area **)** Emitted when another Area2D enters this Area2D. Requires :ref:`monitoring` to be set to ``true``. \ ``area`` the other Area2D. .. rst-class:: classref-item-separator ---- .. _class_Area2D_signal_area_exited: .. rst-class:: classref-signal **area_exited** **(** :ref:`Area2D` area **)** Emitted when another Area2D exits this Area2D. Requires :ref:`monitoring` to be set to ``true``. \ ``area`` the other Area2D. .. rst-class:: classref-item-separator ---- .. _class_Area2D_signal_area_shape_entered: .. rst-class:: classref-signal **area_shape_entered** **(** :ref:`RID` area_rid, :ref:`Area2D` area, :ref:`int` area_shape_index, :ref:`int` local_shape_index **)** Emitted when one of another Area2D's :ref:`Shape2D`\ s enters one of this Area2D's :ref:`Shape2D`\ s. Requires :ref:`monitoring` to be set to ``true``. \ ``area_rid`` the :ref:`RID` of the other Area2D's :ref:`CollisionObject2D` used by the :ref:`Physics2DServer`. \ ``area`` the other Area2D. \ ``area_shape_index`` the index of the :ref:`Shape2D` from the other Area2D. \ ``local_shape_index`` the index of the :ref:`Shape2D` from this Area2D. \ **Example of getting the** :ref:`CollisionShape2D` **node from the shape index:**\ :: var other_shape_owner = area.shape_find_owner(area_shape_index) var other_shape_node = area.shape_owner_get_owner(other_shape_owner) var local_shape_owner = shape_find_owner(local_shape_index) var local_shape_node = shape_owner_get_owner(local_shape_owner) .. rst-class:: classref-item-separator ---- .. _class_Area2D_signal_area_shape_exited: .. rst-class:: classref-signal **area_shape_exited** **(** :ref:`RID` area_rid, :ref:`Area2D` area, :ref:`int` area_shape_index, :ref:`int` local_shape_index **)** Emitted when one of another Area2D's :ref:`Shape2D`\ s exits one of this Area2D's :ref:`Shape2D`\ s. Requires :ref:`monitoring` to be set to ``true``. \ ``area_rid`` the :ref:`RID` of the other Area2D's :ref:`CollisionObject2D` used by the :ref:`Physics2DServer`. \ ``area`` the other Area2D. \ ``area_shape_index`` the index of the :ref:`Shape2D` from the other Area2D. \ ``local_shape_index`` the index of the :ref:`Shape2D` from this Area2D. See also :ref:`area_shape_entered`. .. rst-class:: classref-item-separator ---- .. _class_Area2D_signal_body_entered: .. rst-class:: classref-signal **body_entered** **(** :ref:`Node` body **)** Emitted when a :ref:`PhysicsBody2D` or :ref:`TileMap` enters this Area2D. Requires :ref:`monitoring` to be set to ``true``. :ref:`TileMap`\ s are detected if the :ref:`TileSet` has Collision :ref:`Shape2D`\ s. \ ``body`` the :ref:`Node`, if it exists in the tree, of the other :ref:`PhysicsBody2D` or :ref:`TileMap`. .. rst-class:: classref-item-separator ---- .. _class_Area2D_signal_body_exited: .. rst-class:: classref-signal **body_exited** **(** :ref:`Node` body **)** Emitted when a :ref:`PhysicsBody2D` or :ref:`TileMap` exits this Area2D. Requires :ref:`monitoring` to be set to ``true``. :ref:`TileMap`\ s are detected if the :ref:`TileSet` has Collision :ref:`Shape2D`\ s. \ ``body`` the :ref:`Node`, if it exists in the tree, of the other :ref:`PhysicsBody2D` or :ref:`TileMap`. .. rst-class:: classref-item-separator ---- .. _class_Area2D_signal_body_shape_entered: .. rst-class:: classref-signal **body_shape_entered** **(** :ref:`RID` body_rid, :ref:`Node` body, :ref:`int` body_shape_index, :ref:`int` local_shape_index **)** Emitted when one of a :ref:`PhysicsBody2D` or :ref:`TileMap`'s :ref:`Shape2D`\ s enters one of this Area2D's :ref:`Shape2D`\ s. Requires :ref:`monitoring` to be set to ``true``. :ref:`TileMap`\ s are detected if the :ref:`TileSet` has Collision :ref:`Shape2D`\ s. \ ``body_rid`` the :ref:`RID` of the :ref:`PhysicsBody2D` or :ref:`TileSet`'s :ref:`CollisionObject2D` used by the :ref:`Physics2DServer`. \ ``body`` the :ref:`Node`, if it exists in the tree, of the :ref:`PhysicsBody2D` or :ref:`TileMap`. \ ``body_shape_index`` the index of the :ref:`Shape2D` from the :ref:`PhysicsBody2D` or :ref:`TileMap`. \ ``local_shape_index`` the index of the :ref:`Shape2D` from this Area2D. \ **Example of getting the** :ref:`CollisionShape2D` **node from the shape index:**\ :: var body_shape_owner = body.shape_find_owner(body_shape_index) var body_shape_node = body.shape_owner_get_owner(body_shape_owner) var local_shape_owner = shape_find_owner(local_shape_index) var local_shape_node = shape_owner_get_owner(local_shape_owner) .. rst-class:: classref-item-separator ---- .. _class_Area2D_signal_body_shape_exited: .. rst-class:: classref-signal **body_shape_exited** **(** :ref:`RID` body_rid, :ref:`Node` body, :ref:`int` body_shape_index, :ref:`int` local_shape_index **)** Emitted when one of a :ref:`PhysicsBody2D` or :ref:`TileMap`'s :ref:`Shape2D`\ s exits one of this Area2D's :ref:`Shape2D`\ s. Requires :ref:`monitoring` to be set to ``true``. :ref:`TileMap`\ s are detected if the :ref:`TileSet` has Collision :ref:`Shape2D`\ s. \ ``body_rid`` the :ref:`RID` of the :ref:`PhysicsBody2D` or :ref:`TileSet`'s :ref:`CollisionObject2D` used by the :ref:`Physics2DServer`. \ ``body`` the :ref:`Node`, if it exists in the tree, of the :ref:`PhysicsBody2D` or :ref:`TileMap`. \ ``body_shape_index`` the index of the :ref:`Shape2D` from the :ref:`PhysicsBody2D` or :ref:`TileMap`. \ ``local_shape_index`` the index of the :ref:`Shape2D` from this Area2D. See also :ref:`body_shape_entered`. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Enumerations ------------ .. _enum_Area2D_SpaceOverride: .. rst-class:: classref-enumeration enum **SpaceOverride**: .. _class_Area2D_constant_SPACE_OVERRIDE_DISABLED: .. rst-class:: classref-enumeration-constant :ref:`SpaceOverride` **SPACE_OVERRIDE_DISABLED** = ``0`` This area does not affect gravity/damping. .. _class_Area2D_constant_SPACE_OVERRIDE_COMBINE: .. rst-class:: classref-enumeration-constant :ref:`SpaceOverride` **SPACE_OVERRIDE_COMBINE** = ``1`` This area adds its gravity/damping values to whatever has been calculated so far (in :ref:`priority` order). .. _class_Area2D_constant_SPACE_OVERRIDE_COMBINE_REPLACE: .. rst-class:: classref-enumeration-constant :ref:`SpaceOverride` **SPACE_OVERRIDE_COMBINE_REPLACE** = ``2`` This area adds its gravity/damping values to whatever has been calculated so far (in :ref:`priority` order), ignoring any lower priority areas. .. _class_Area2D_constant_SPACE_OVERRIDE_REPLACE: .. rst-class:: classref-enumeration-constant :ref:`SpaceOverride` **SPACE_OVERRIDE_REPLACE** = ``3`` This area replaces any gravity/damping, even the defaults, ignoring any lower priority areas. .. _class_Area2D_constant_SPACE_OVERRIDE_REPLACE_COMBINE: .. rst-class:: classref-enumeration-constant :ref:`SpaceOverride` **SPACE_OVERRIDE_REPLACE_COMBINE** = ``4`` This area replaces any gravity/damping calculated so far (in :ref:`priority` order), but keeps calculating the rest of the areas. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_Area2D_property_angular_damp: .. rst-class:: classref-property :ref:`float` **angular_damp** = ``1.0`` .. rst-class:: classref-property-setget - void **set_angular_damp** **(** :ref:`float` value **)** - :ref:`float` **get_angular_damp** **(** **)** The rate at which objects stop spinning in this area. Represents the angular velocity lost per second. See :ref:`ProjectSettings.physics/2d/default_angular_damp` for more details about damping. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_audio_bus_name: .. rst-class:: classref-property :ref:`String` **audio_bus_name** = ``"Master"`` .. rst-class:: classref-property-setget - void **set_audio_bus_name** **(** :ref:`String` value **)** - :ref:`String` **get_audio_bus_name** **(** **)** The name of the area's audio bus. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_audio_bus_override: .. rst-class:: classref-property :ref:`bool` **audio_bus_override** = ``false`` .. rst-class:: classref-property-setget - void **set_audio_bus_override** **(** :ref:`bool` value **)** - :ref:`bool` **is_overriding_audio_bus** **(** **)** If ``true``, the area's audio bus overrides the default audio bus. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_gravity: .. rst-class:: classref-property :ref:`float` **gravity** = ``98.0`` .. rst-class:: classref-property-setget - void **set_gravity** **(** :ref:`float` value **)** - :ref:`float` **get_gravity** **(** **)** The area's gravity intensity (in pixels per second squared). This value multiplies the gravity vector. This is useful to alter the force of gravity without altering its direction. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_gravity_distance_scale: .. rst-class:: classref-property :ref:`float` **gravity_distance_scale** = ``0.0`` .. rst-class:: classref-property-setget - void **set_gravity_distance_scale** **(** :ref:`float` value **)** - :ref:`float` **get_gravity_distance_scale** **(** **)** The falloff factor for point gravity. The greater the value, the faster gravity decreases with distance. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_gravity_point: .. rst-class:: classref-property :ref:`bool` **gravity_point** = ``false`` .. rst-class:: classref-property-setget - void **set_gravity_is_point** **(** :ref:`bool` value **)** - :ref:`bool` **is_gravity_a_point** **(** **)** If ``true``, gravity is calculated from a point (set via :ref:`gravity_vec`). See also :ref:`space_override`. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_gravity_vec: .. rst-class:: classref-property :ref:`Vector2` **gravity_vec** = ``Vector2( 0, 1 )`` .. rst-class:: classref-property-setget - void **set_gravity_vector** **(** :ref:`Vector2` value **)** - :ref:`Vector2` **get_gravity_vector** **(** **)** The area's gravity vector (not normalized). If gravity is a point (see :ref:`gravity_point`), this will be the point of attraction. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_linear_damp: .. rst-class:: classref-property :ref:`float` **linear_damp** = ``0.1`` .. rst-class:: classref-property-setget - void **set_linear_damp** **(** :ref:`float` value **)** - :ref:`float` **get_linear_damp** **(** **)** The rate at which objects stop moving in this area. Represents the linear velocity lost per second. See :ref:`ProjectSettings.physics/2d/default_linear_damp` for more details about damping. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_monitorable: .. rst-class:: classref-property :ref:`bool` **monitorable** = ``true`` .. rst-class:: classref-property-setget - void **set_monitorable** **(** :ref:`bool` value **)** - :ref:`bool` **is_monitorable** **(** **)** If ``true``, other monitoring areas can detect this area. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_monitoring: .. rst-class:: classref-property :ref:`bool` **monitoring** = ``true`` .. rst-class:: classref-property-setget - void **set_monitoring** **(** :ref:`bool` value **)** - :ref:`bool` **is_monitoring** **(** **)** If ``true``, the area detects bodies or areas entering and exiting it. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_priority: .. rst-class:: classref-property :ref:`float` **priority** = ``0.0`` .. rst-class:: classref-property-setget - void **set_priority** **(** :ref:`float` value **)** - :ref:`float` **get_priority** **(** **)** The area's priority. Higher priority areas are processed first. .. rst-class:: classref-item-separator ---- .. _class_Area2D_property_space_override: .. rst-class:: classref-property :ref:`SpaceOverride` **space_override** = ``0`` .. rst-class:: classref-property-setget - void **set_space_override_mode** **(** :ref:`SpaceOverride` value **)** - :ref:`SpaceOverride` **get_space_override_mode** **(** **)** Override mode for gravity and damping calculations within this area. See :ref:`SpaceOverride` for possible values. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_Area2D_method_get_overlapping_areas: .. rst-class:: classref-method :ref:`Array` **get_overlapping_areas** **(** **)** |const| Returns a list of intersecting **Area2D**\ s. The overlapping area's :ref:`CollisionObject2D.collision_layer` must be part of this area's :ref:`CollisionObject2D.collision_mask` in order to be detected. For performance reasons (collisions are all processed at the same time) this list is modified once during the physics step, not immediately after objects are moved. Consider using signals instead. .. rst-class:: classref-item-separator ---- .. _class_Area2D_method_get_overlapping_bodies: .. rst-class:: classref-method :ref:`Array` **get_overlapping_bodies** **(** **)** |const| Returns a list of intersecting :ref:`PhysicsBody2D`\ s. The overlapping body's :ref:`CollisionObject2D.collision_layer` must be part of this area's :ref:`CollisionObject2D.collision_mask` in order to be detected. For performance reasons (collisions are all processed at the same time) this list is modified once during the physics step, not immediately after objects are moved. Consider using signals instead. .. rst-class:: classref-item-separator ---- .. _class_Area2D_method_overlaps_area: .. rst-class:: classref-method :ref:`bool` **overlaps_area** **(** :ref:`Node` area **)** |const| If ``true``, the given area overlaps the Area2D. \ **Note:** The result of this test is not immediate after moving objects. For performance, the list of overlaps is updated once per frame and before the physics step. Consider using signals instead. .. rst-class:: classref-item-separator ---- .. _class_Area2D_method_overlaps_body: .. rst-class:: classref-method :ref:`bool` **overlaps_body** **(** :ref:`Node` body **)** |const| If ``true``, the given physics body overlaps the Area2D. \ **Note:** The result of this test is not immediate after moving objects. For performance, list of overlaps is updated once per frame and before the physics step. Consider using signals instead. The ``body`` argument can either be a :ref:`PhysicsBody2D` or a :ref:`TileMap` instance (while TileMaps are not physics bodies themselves, they register their tiles with collision shapes as a virtual physics body). .. |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.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`