Server interface for low-level 2D physics access.
PhysicsServer2D is the server responsible for all 2D physics. It can create many kinds of physics objects, but does not insert them on the node tree.
Adds a shape to the area, along with a transform matrix. Shapes are usually referenced by their index, so you should track which shape has a given index.
Assigns the area to a descendant of [Object], so it can exist in the node tree.
Removes all shapes from an area. It does not delete the shapes, so they can be reassigned later.
Creates an [Area2D]. After creating an [Area2D] with this method, assign it to a space using [method area_set_space] to use the created [Area2D] in the physics world.
Gets the instance ID of the object the area is assigned to.
Returns an area parameter value. See [enum AreaParameter] for a list of available parameters.
Returns the [RID] of the nth shape of an area.
Returns the number of shapes assigned to an area.
Returns the transform matrix of a shape within an area.
Returns the space assigned to the area.
Returns the transform matrix for an area.
Removes a shape from an area. It does not delete the shape, so it can be reassigned later.
Assigns the area to one or many physics layers.
Sets which physics layers the area will monitor.
Sets the function to call when any body/area enters or exits the area. This callback will be called for any object interacting with the area, and takes five parameters:
1: [constant AREA_BODY_ADDED] or [constant AREA_BODY_REMOVED], depending on whether the object entered or exited the area.
2: [RID] of the object that entered/exited the area.
3: Instance ID of the object that entered/exited the area.
4: The shape index of the object that entered/exited the area.
5: The shape index of the area where the object entered/exited.
Sets the value for an area parameter. See [enum AreaParameter] for a list of available parameters.
Substitutes a given area shape by another. The old shape is selected by its index, the new one by its [RID].
Disables a given shape in an area.
Sets the transform matrix for an area shape.
Assigns a space to the area.
Sets the transform matrix for an area.
Adds a body to the list of bodies exempt from collisions.
Adds a constant directional force without affecting rotation that keeps being applied over time until cleared with [code]body_set_constant_force(body, Vector2(0, 0))[/code].
This is equivalent to using [method body_add_constant_force] at the body's center of mass.
Adds a constant positioned force to the body that keeps being applied over time until cleared with [code]body_set_constant_force(body, Vector2(0, 0))[/code].
[param position] is the offset from the body origin in global coordinates.
Adds a constant rotational force without affecting position that keeps being applied over time until cleared with [code]body_set_constant_torque(body, 0)[/code].
Adds a shape to the body, along with a transform matrix. Shapes are usually referenced by their index, so you should track which shape has a given index.
Applies a directional force without affecting rotation. A force is time dependent and meant to be applied every physics update.
This is equivalent to using [method body_apply_force] at the body's center of mass.
Applies a directional impulse without affecting rotation.
An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
This is equivalent to using [method body_apply_impulse] at the body's center of mass.
Applies a positioned force to the body. A force is time dependent and meant to be applied every physics update.
[param position] is the offset from the body origin in global coordinates.
Applies a positioned impulse to the body.
An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
[param position] is the offset from the body origin in global coordinates.
Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.
Applies a rotational impulse to the body without affecting the position.
An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).
Assigns the area to a descendant of [Object], so it can exist in the node tree.
Removes all shapes from a body.
Creates a physics body.
Returns the physics layer or layers a body belongs to.
Returns the physics layer or layers a body can collide with.
Returns the body's collision priority.
Returns the body's total constant positional forces applied during each physics update.
See [method body_add_constant_force] and [method body_add_constant_central_force].
Returns the body's total constant rotational forces applied during each physics update.
See [method body_add_constant_torque].
Returns the continuous collision detection mode.
Returns the [PhysicsDirectBodyState2D] of the body. Returns [code]null[/code] if the body is destroyed or removed from the physics space.
Returns the maximum contacts that can be reported. See [method body_set_max_contacts_reported].
Returns the body mode.
Gets the instance ID of the object the area is assigned to.
Returns the value of a body parameter. See [enum BodyParameter] for a list of available parameters.
Returns the [RID] of the nth shape of a body.
Returns the number of shapes assigned to a body.
Returns the transform matrix of a body shape.
Returns the [RID] of the space assigned to a body.
Returns a body state.
Returns whether a body uses a callback function to calculate its own physics (see [method body_set_force_integration_callback]).
Removes a body from the list of bodies exempt from collisions.
Removes a shape from a body. The shape is not deleted, so it can be reused afterwards.
Restores the default inertia and center of mass based on shapes to cancel any custom values previously set using [method body_set_param].
Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
Sets the physics layer or layers a body belongs to.
Sets the physics layer or layers a body can collide with.
Sets the body's collision priority.
Sets the body's total constant positional forces applied during each physics update.
See [method body_add_constant_force] and [method body_add_constant_central_force].
Sets the body's total constant rotational forces applied during each physics update.
See [method body_add_constant_torque].
Sets the continuous collision detection mode using one of the [enum CCDMode] constants.
Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided.
Sets the function used to calculate physics for an object, if that object allows it (see [method body_set_omit_force_integration]).
The force integration function takes 2 arguments:
[code]state:[/code] [PhysicsDirectBodyState2D] used to retrieve and modify the body's state.
[code]userdata:[/code] Optional user data, if it was passed when calling [code]body_set_force_integration_callback[/code].
Sets the maximum contacts to report. Bodies can keep a log of the contacts with other bodies. This is enabled by setting the maximum number of contacts reported to a number greater than 0.
Sets the body mode using one of the [enum BodyMode] constants.
Sets whether a body uses a callback function to calculate its own physics (see [method body_set_force_integration_callback]).
Sets a body parameter. See [enum BodyParameter] for a list of available parameters.
Substitutes a given body shape by another. The old shape is selected by its index, the new one by its [RID].
Enables one way collision on body if [param enable] is [code]true[/code].
Disables shape in body if [param disabled] is [code]true[/code].
Sets the transform matrix for a body shape.
Assigns a space to the body (see [method space_create]).
Sets a body state using one of the [enum BodyState] constants.
Note that the method doesn't take effect immediately. The state will change on the next physics frame.
Returns [code]true[/code] if a collision would result from moving along a motion vector from a given point in space. [PhysicsTestMotionParameters2D] is passed to set motion parameters. [PhysicsTestMotionResult2D] can be passed to return additional information.
Returns the value of a damped spring joint parameter. See [enum DampedSpringParam] for a list of available parameters.
Sets a damped spring joint parameter. See [enum DampedSpringParam] for a list of available parameters.
Destroys any of the objects created by PhysicsServer2D. If the [RID] passed is not one of the objects that can be created by PhysicsServer2D, an error will be sent to the console.
Returns information about the current state of the 2D physics engine. See [enum ProcessInfo] for a list of available states.
Returns the value of a joint parameter.
Returns a joint's type (see [enum JointType]).
Sets a joint parameter. See [enum JointParam] for a list of available parameters.
Activates or deactivates the 2D physics engine.
Returns the shape data.
Returns a shape's type (see [enum ShapeType]).
Sets the shape data that defines its shape and size. The data to be passed depends on the kind of shape created [method shape_get_type].
Creates a space. A space is a collection of parameters for the physics engine that can be assigned to an area or a body. It can be assigned to an area with [method area_set_space], or to a body with [method body_set_space].
Returns the state of a space, a [PhysicsDirectSpaceState2D]. This object can be used to make collision/intersection queries.
Returns the value of a space parameter.
Returns whether the space is active.
Marks a space as active. It will not have an effect, unless it is assigned to an area or body.
Sets the value for a space parameter. See [enum SpaceParameter] for a list of available parameters.
Constant to set/get the maximum distance a pair of bodies has to move before their collision status has to be recalculated.
Constant to set/get the maximum distance a shape can be from another before they are considered separated and the contact is discarded.
Constant to set/get the maximum distance a shape can penetrate another shape before it is considered a collision.
Constant to set/get the default solver bias for all physics contacts. A solver bias is a factor controlling how much two objects "rebound", after overlapping, to avoid leaving them in that state because of numerical imprecision.
Constant to set/get the threshold linear velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given.
Constant to set/get the threshold angular velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given.
Constant to set/get the maximum time of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after this time.
Constant to set/get the default solver bias for all physics constraints. A solver bias is a factor controlling how much two objects "rebound", after violating a constraint, to avoid leaving them in that state because of numerical imprecision.
Constant to set/get the number of solver iterations for all contacts and constraints. The greater the number of iterations, the more accurate the collisions will be. However, a greater number of iterations requires more CPU power, which can decrease performance.
This is the constant for creating world boundary shapes. A world boundary shape is an [i]infinite[/i] line with an origin point, and a normal. Thus, it can be used for front/behind checks.
This is the constant for creating separation ray shapes. A separation ray is defined by a length and separates itself from what is touching its far endpoint. Useful for character controllers.
This is the constant for creating segment shapes. A segment shape is a [i]finite[/i] line from a point A to a point B. It can be checked for intersections.
This is the constant for creating circle shapes. A circle shape only has a radius. It can be used for intersections and inside/outside checks.
This is the constant for creating rectangle shapes. A rectangle shape is defined by a width and a height. It can be used for intersections and inside/outside checks.
This is the constant for creating capsule shapes. A capsule shape is defined by a radius and a length. It can be used for intersections and inside/outside checks.
This is the constant for creating convex polygon shapes. A polygon is defined by a list of points. It can be used for intersections and inside/outside checks. Unlike the [member CollisionPolygon2D.polygon] property, polygons modified with [method shape_set_data] do not verify that the points supplied form is a convex polygon.
This is the constant for creating concave polygon shapes. A polygon is defined by a list of points. It can be used for intersections checks, but not for inside/outside checks.
This constant is used internally by the engine. Any attempt to create this kind of shape results in an error.
Constant to set/get gravity override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
Constant to set/get gravity strength in an area.
Constant to set/get gravity vector/center in an area.
Constant to set/get whether the gravity vector of an area is a direction, or a center point.
Constant to set/get the falloff factor for point gravity of an area. The greater this value is, the faster the strength of gravity decreases with the square of distance.
This constant was used to set/get the falloff factor for point gravity. It has been superseded by [constant AREA_PARAM_GRAVITY_DISTANCE_SCALE].
Constant to set/get linear damping override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
Constant to set/get the linear damping factor of an area.
Constant to set/get angular damping override mode in an area. See [enum AreaSpaceOverrideMode] for possible values.
Constant to set/get the angular damping factor of an area.
Constant to set/get the priority (order of processing) of an area.
This area does not affect gravity/damp. These are generally areas that exist only to detect collisions, and objects entering or exiting them.
This area adds its gravity/damp values to whatever has been calculated so far. This way, many overlapping areas can combine their physics to make interesting effects.
This area adds its gravity/damp values to whatever has been calculated so far. Then stops taking into account the rest of the areas, even the default one.
This area replaces any gravity/damp, even the default one, and stops taking into account the rest of the areas.
This area replaces any gravity/damp calculated so far, but keeps calculating the rest of the areas, down to the default one.
Constant for static bodies. In this mode, a body can be only moved by user code and doesn't collide with other bodies along its path when moved.
Constant for kinematic bodies. In this mode, a body can be only moved by user code and collides with other bodies along its path.
Constant for rigid bodies. In this mode, a body can be pushed by other bodies and has forces applied.
Constant for linear rigid bodies. In this mode, a body can not rotate, and only its linear velocity is affected by external forces.
Constant to set/get a body's bounce factor.
Constant to set/get a body's friction.
Constant to set/get a body's mass.
Constant to set/get a body's inertia.
Constant to set/get a body's center of mass position in the body's local coordinate system.
Constant to set/get a body's gravity multiplier.
Constant to set/get a body's linear dampening mode. See [enum BodyDampMode] for possible values.
Constant to set/get a body's angular dampening mode. See [enum BodyDampMode] for possible values.
Constant to set/get a body's linear dampening factor.
Constant to set/get a body's angular dampening factor.
Represents the size of the [enum BodyParameter] enum.
The body's damping value is added to any value set in areas or the default value.
The body's damping value replaces any value set in areas or the default value.
Constant to set/get the current transform matrix of the body.
Constant to set/get the current linear velocity of the body.
Constant to set/get the current angular velocity of the body.
Constant to sleep/wake up a body, or to get whether it is sleeping.
Constant to set/get whether the body can sleep.
Constant to create pin joints.
Constant to create groove joints.
Constant to create damped spring joints.
Represents the size of the [enum JointType] enum.
Sets the resting length of the spring joint. The joint will always try to go to back this length when pulled apart.
Sets the stiffness of the spring joint. The joint applies a force equal to the stiffness times the distance from its resting length.
Sets the damping ratio of the spring joint. A value of 0 indicates an undamped spring, while 1 causes the system to reach equilibrium as fast as possible (critical damping).
Disables continuous collision detection. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
Enables continuous collision detection by raycasting. It is faster than shapecasting, but less precise.
Enables continuous collision detection by shapecasting. It is the slowest CCD method, and the most precise.
The value of the first parameter and area callback function receives, when an object enters one of its shapes.
The value of the first parameter and area callback function receives, when an object exits one of its shapes.
Constant to get the number of objects that are not sleeping.
Constant to get the number of possible collisions.
Constant to get the number of space regions where a collision could occur.