Area2D
An overlap-detection and local physics-field area.
Area2D detects bodies/areas and can override gravity, damping and an audio bus. It does not become a solid wall. Its Mask tests target Layer; detection requires Monitoring and an active shape.
Monitorable permits other areas to detect this area and does not replace Monitoring. Overlap lists update on physics ticks. In entry/exit signals, set a handled flag before deferring Monitoring/shape changes. Zero gravity does not clear existing velocity.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
Area2DConstructor
public Area2D();Properties15
AngularDampProperty
public float AngularDamp { get; set; }The rate at which objects stop spinning in this area. Represents the angular velocity lost per second.
See ProjectSettings.physics/2d/default_angular_damp for more details about damping.
AngularDampSpaceOverrideProperty
public Area2D.SpaceOverride AngularDampSpaceOverride { get; set; }Override mode for angular damping calculations within this area.
AudioBusNameProperty
public StringName AudioBusName { get; set; }The name of the area's audio bus.
AudioBusOverrideProperty
public bool AudioBusOverride { get; set; }If true, the area's audio bus overrides the default audio bus.
GravityProperty
public float Gravity { get; set; }The area's gravity intensity (in pixels per second squared). This value multiplies the gravity direction. This is useful to alter the force of gravity without altering its direction.
GravityDirectionProperty
public Vector2 GravityDirection { get; set; }The area's gravity vector (not normalized).
GravityPointProperty
public bool GravityPoint { get; set; }If true, gravity is calculated from a point (set via Area2D.GravityPointCenter). See also Area2D.GravitySpaceOverride.
GravityPointCenterProperty
public Vector2 GravityPointCenter { get; set; }If gravity is a point (see Area2D.GravityPoint), this will be the point of attraction.
GravityPointUnitDistanceProperty
public float GravityPointUnitDistance { get; set; }The distance at which the gravity strength is equal to Area2D.Gravity. For example, on a planet 100 pixels in radius with a surface gravity of 4.0 px/s², set the Area2D.Gravity to 4.0 and the unit distance to 100.0. The gravity will have falloff according to the inverse square law, so in the example, at 200 pixels from the center the gravity will be 1.0 px/s² (twice the distance, 1/4th the gravity), at 50 pixels it will be 16.0 px/s² (half the distance, 4× the gravity), and so on.
The above is true only when the unit distance is a positive number. When this is set to 0.0, the gravity will be constant regardless of distance.
GravitySpaceOverrideProperty
public Area2D.SpaceOverride GravitySpaceOverride { get; set; }Controls combining area gravity with other fields/the world. Gravity = 0 while Disabled does not enable zero gravity; choose an appropriate replacement mode.
LinearDampProperty
public float LinearDamp { get; set; }The rate at which objects stop moving in this area. Represents the linear velocity lost per second.
See ProjectSettings.physics/2d/default_linear_damp for more details about damping.
LinearDampSpaceOverrideProperty
public Area2D.SpaceOverride LinearDampSpaceOverride { get; set; }Override mode for linear damping calculations within this area.
MonitorableProperty
public bool Monitorable { get; set; }Allows other monitoring areas to detect this Area2D. It does not enable this area's own Monitoring. Defer changes in locked physics callbacks.
MonitoringProperty
public bool Monitoring { get; set; }Enables this area to detect bodies and areas. Distinct from Monitorable. Change through SetDeferred inside enter/exit handlers because direct changes are blocked during notification.
PriorityProperty
public int Priority { get; set; }The area's priority. Higher priority areas are processed first. The World2D's physics is always processed last, after all areas.
Methods36
GetAngularDampfloat
public float GetAngularDamp();floatGetAngularDampSpaceOverrideModeArea2D.SpaceOverride
public Area2D.SpaceOverride GetAngularDampSpaceOverrideMode();Area2D.SpaceOverrideGetAudioBusNameStringName
public StringName GetAudioBusName();StringNameGetGravityfloat
public float GetGravity();floatGetGravityDirectionVector2
public Vector2 GetGravityDirection();Vector2GetGravityPointCenterVector2
public Vector2 GetGravityPointCenter();Vector2GetGravityPointUnitDistancefloat
public float GetGravityPointUnitDistance();floatGetGravitySpaceOverrideModeArea2D.SpaceOverride
public Area2D.SpaceOverride GetGravitySpaceOverrideMode();Area2D.SpaceOverrideGetLinearDampfloat
public float GetLinearDamp();floatGetLinearDampSpaceOverrideModeArea2D.SpaceOverride
public Area2D.SpaceOverride GetLinearDampSpaceOverrideMode();Area2D.SpaceOverrideGetOverlappingAreasReckfell.Collections.Array<Area2D>
public Reckfell.Collections.Array<Area2D> GetOverlappingAreas();Returns a list of intersecting Area2Ds. The overlapping area's CollisionObject2D.CollisionLayer must be part of this area's CollisionObject2D.CollisionMask 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.
Reckfell.Collections.Array<Area2D>GetOverlappingBodiesReckfell.Collections.Array<Entity2D>
public Reckfell.Collections.Array<Entity2D> GetOverlappingBodies();Returns detected bodies from physics-updated state. Immediately after moving or adding a shape, the list may still be old. Requires Monitoring=true; use BodyEntered for entry reactions.
Reckfell.Collections.Array<Entity2D>Entity2D array of currently detected bodies. No overlaps can produce an empty array; with Monitoring disabled the method reports an error and also returns an empty array.
GetPriorityint
public int GetPriority();intHasOverlappingAreasbool
public bool HasOverlappingAreas();Returns true if intersecting any Area2Ds, otherwise returns false. The overlapping area's CollisionObject2D.CollisionLayer must be part of this area's CollisionObject2D.CollisionMask in order to be detected.
For performance reasons (collisions are all processed at the same time) the list of overlapping areas is modified once during the physics step, not immediately after objects are moved. Consider using signals instead.
boolHasOverlappingBodiesbool
public bool HasOverlappingBodies();Returns true if intersecting any PhysicsBody2Ds or TileMaps, otherwise returns false. The overlapping body's CollisionObject2D.CollisionLayer must be part of this area's CollisionObject2D.CollisionMask in order to be detected.
For performance reasons (collisions are all processed at the same time) the list of overlapping bodies is modified once during the physics step, not immediately after objects are moved. Consider using signals instead.
boolIsGravityAPointbool
public bool IsGravityAPoint();boolIsMonitorablebool
public bool IsMonitorable();boolIsMonitoringbool
public bool IsMonitoring();boolIsOverridingAudioBusbool
public bool IsOverridingAudioBus();boolOverlapsAreabool
public bool OverlapsArea(Entity area);Returns true if the given Area2D intersects or overlaps this Area2D, false otherwise.
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.
| Name | Type | Default |
|---|---|---|
area | Entity | — |
boolOverlapsBodybool
public bool OverlapsBody(Entity body);Returns true if the given physics body intersects or overlaps this Area2D, false otherwise.
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 PhysicsBody2D or a TileMap instance. While TileMaps are not physics bodies themselves, they register their tiles with collision shapes as a virtual physics body.
| Name | Type | Default |
|---|---|---|
body | Entity | — |
boolSetAngularDampvoid
public void SetAngularDamp(float angularDamp);| Name | Type | Default |
|---|---|---|
angularDamp | float | — |
SetAngularDampSpaceOverrideModevoid
public void SetAngularDampSpaceOverrideMode(Area2D.SpaceOverride spaceOverrideMode);| Name | Type | Default |
|---|---|---|
spaceOverrideMode | Area2D.SpaceOverride | — |
SetAudioBusNamevoid
public void SetAudioBusName(StringName name);| Name | Type | Default |
|---|---|---|
name | StringName | — |
SetAudioBusOverridevoid
public void SetAudioBusOverride(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetGravityvoid
public void SetGravity(float gravity);| Name | Type | Default |
|---|---|---|
gravity | float | — |
SetGravityDirectionvoid
public void SetGravityDirection(Vector2 direction);| Name | Type | Default |
|---|---|---|
direction | Vector2 | — |
SetGravityIsPointvoid
public void SetGravityIsPoint(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetGravityPointCentervoid
public void SetGravityPointCenter(Vector2 center);| Name | Type | Default |
|---|---|---|
center | Vector2 | — |
SetGravityPointUnitDistancevoid
public void SetGravityPointUnitDistance(float distanceScale);| Name | Type | Default |
|---|---|---|
distanceScale | float | — |
SetGravitySpaceOverrideModevoid
public void SetGravitySpaceOverrideMode(Area2D.SpaceOverride spaceOverrideMode);| Name | Type | Default |
|---|---|---|
spaceOverrideMode | Area2D.SpaceOverride | — |
SetLinearDampvoid
public void SetLinearDamp(float linearDamp);| Name | Type | Default |
|---|---|---|
linearDamp | float | — |
SetLinearDampSpaceOverrideModevoid
public void SetLinearDampSpaceOverrideMode(Area2D.SpaceOverride spaceOverrideMode);| Name | Type | Default |
|---|---|---|
spaceOverrideMode | Area2D.SpaceOverride | — |
SetMonitorablevoid
public void SetMonitorable(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetMonitoringvoid
public void SetMonitoring(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetPriorityvoid
public void SetPriority(int priority);| Name | Type | Default |
|---|---|---|
priority | int | — |
Signals and events8
AreaEnteredEvent
public event Area2D.AreaEnteredEventHandler AreaEntered;Emitted when the received area enters this area. Requires Area2D.Monitoring to be set to true.
| Name | Type | Default |
|---|---|---|
area | Area2D | — |
AreaExitedEvent
public event Area2D.AreaExitedEventHandler AreaExited;Emitted when the received area exits this area. Requires Area2D.Monitoring to be set to true.
| Name | Type | Default |
|---|---|---|
area | Area2D | — |
AreaShapeEnteredEvent
public event Area2D.AreaShapeEnteredEventHandler AreaShapeEntered;Emitted when a Shape2D of the received area enters a shape of this area. Requires Area2D.Monitoring to be set to true.
local_shape_index and area_shape_index contain indices of the interacting shapes from this area and the other area, respectively. area_rid contains the Rid of the other area. These values can be used with the PhysicsServer2D.
Example: Get the CollisionShape2D node from the shape index:
| Name | Type | Default |
|---|---|---|
areaRid | Rid | — |
area | Area2D | — |
areaShapeIndex | long | — |
localShapeIndex | long | — |
AreaShapeExitedEvent
public event Area2D.AreaShapeExitedEventHandler AreaShapeExited;Emitted when a Shape2D of the received area exits a shape of this area. Requires Area2D.Monitoring to be set to true.
See also Area2D.AreaShapeEntered.
| Name | Type | Default |
|---|---|---|
areaRid | Rid | — |
area | Area2D | — |
areaShapeIndex | long | — |
localShapeIndex | long | — |
BodyEnteredEvent
public event Area2D.BodyEnteredEventHandler BodyEntered;Emitted when the received body enters this area. body can be a PhysicsBody2D or a TileMap. TileMaps are detected if their TileSet has collision shapes configured. Requires Area2D.Monitoring to be set to true.
| Name | Type | Default |
|---|---|---|
body | Entity2D | — |
BodyExitedEvent
public event Area2D.BodyExitedEventHandler BodyExited;Emitted when the received body exits this area. body can be a PhysicsBody2D or a TileMap. TileMaps are detected if their TileSet has collision shapes configured. Requires Area2D.Monitoring to be set to true.
| Name | Type | Default |
|---|---|---|
body | Entity2D | — |
BodyShapeEnteredEvent
public event Area2D.BodyShapeEnteredEventHandler BodyShapeEntered;Emitted when a Shape2D of the received body enters a shape of this area. body can be a PhysicsBody2D or a TileMap. TileMaps are detected if their TileSet has collision shapes configured. Requires Area2D.Monitoring to be set to true.
local_shape_index and body_shape_index contain indices of the interacting shapes from this area and the interacting body, respectively. body_rid contains the Rid of the body. These values can be used with the PhysicsServer2D.
Example: Get the CollisionShape2D node from the shape index:
| Name | Type | Default |
|---|---|---|
bodyRid | Rid | — |
body | Entity2D | — |
bodyShapeIndex | long | — |
localShapeIndex | long | — |
BodyShapeExitedEvent
public event Area2D.BodyShapeExitedEventHandler BodyShapeExited;Emitted when a Shape2D of the received body exits a shape of this area. body can be a PhysicsBody2D or a TileMap. TileMaps are detected if their TileSet has collision shapes configured. Requires Area2D.Monitoring to be set to true.
See also Area2D.BodyShapeEntered.
| Name | Type | Default |
|---|---|---|
bodyRid | Rid | — |
body | Entity2D | — |
bodyShapeIndex | long | — |
localShapeIndex | long | — |
Area2D.SpaceOverride
| Value | Description |
|---|---|
Combine = 1 | This area adds its gravity/damping values to whatever has been calculated so far (in |
CombineReplace = 2 | This area adds its gravity/damping values to whatever has been calculated so far (in |
Disabled = 0 | This area does not affect gravity/damping. |
Replace = 3 | This area replaces any gravity/damping, even the defaults, ignoring any lower priority areas. |
ReplaceCombine = 4 | This area replaces any gravity/damping calculated so far (in |