Class PhysicsServer2D
A server interface for low-level 2D physics access.
- Inheritance
-
PhysicsServer2D
- Derived
Remarks
PhysicsServer2D is the server responsible for all 2D physics. It can directly create and manipulate all physics objects:
A space is a self-contained world for a physics simulation. It contains bodies, areas, and joints. Its state can be queried for collision and intersection information, and several parameters of the simulation can be modified.
A shape is a geometric shape such as a circle, a rectangle, a capsule, or a polygon. It can be used for collision detection by adding it to a body/area, possibly with an extra transformation relative to the body/area's origin. Bodies/areas can have multiple (transformed) shapes added to them, and a single shape can be added to bodies/areas multiple times with different local transformations.
A body is a physical object which can be in static, kinematic, or rigid mode. Its state (such as position and velocity) can be queried and updated. A force integration callback can be set to customize the body's physics.
An area is a region in space which can be used to detect bodies and areas entering and exiting it. A body monitoring callback can be set to report entering/exiting body shapes, and similarly an area monitoring callback can be set. Gravity and damping can be overridden within the area by setting area parameters.
A joint is a constraint, either between two bodies or on one body relative to a point. Parameters such as the joint bias and the rest length of a spring joint can be adjusted.
Physics objects in PhysicsServer2D may be created and manipulated independently; they do not have to be tied to nodes in the scene tree.
Note: All the 2D physics nodes use the physics server internally. Adding a physics node to the scene tree will cause a corresponding physics object to be created in the physics server. A rigid body node registers a callback that updates the node's transform with the transform of the respective body object in the physics server (every physics update). An area node registers a callback to inform the area node about overlaps with the respective area object in the physics server. The raycast node queries the direct state of the relevant space in the physics server.
Methods
area_add_shape(RID, RID, Transform2D, bool)
Adds a shape to the area, with the given local transform. The shape (together with its transform
and disabled
properties) is added to an array of shapes, and the shapes of an area are usually referenced by their index in this array.
void area_add_shape(RID area, RID shape, Transform2D transform, bool disabled)
Parameters
area
RIDshape
RIDtransform
Transform2Ddisabled
bool
area_attach_canvas_instance_id(RID, int)
Attaches the ObjectID
of a canvas to the area. Use get_instance_id to get the ObjectID
of a CanvasLayer.
void area_attach_canvas_instance_id(RID area, int id)
Parameters
area_attach_object_instance_id(RID, int)
Attaches the ObjectID
of an Object to the area. Use get_instance_id to get the ObjectID
of a CollisionObject2D.
void area_attach_object_instance_id(RID area, int id)
Parameters
area_clear_shapes(RID)
Removes all shapes from the area. This does not delete the shapes themselves, so they can continue to be used elsewhere or added back later.
void area_clear_shapes(RID area)
Parameters
area
RID
area_create
Creates a 2D area object in the physics server, and returns the RID that identifies it. The default settings for the created area include a collision layer and mask set to 1
, and monitorable
set to false
.
Use PhysicsServer2D.area_add_shape to add shapes to it, use PhysicsServer2D.area_set_transform to set its transform, and use PhysicsServer2D.area_set_space to add the area to a space. If you want the area to be detectable use PhysicsServer2D.area_set_monitorable.
RID area_create
area_get_canvas_instance_id(RID)
Qualifiers: const
Returns the ObjectID
of the canvas attached to the area. Use @GlobalScope.instance_from_id to retrieve a CanvasLayer from a nonzero ObjectID
.
int area_get_canvas_instance_id(RID area)
Parameters
area
RID
area_get_collision_layer(RID)
Qualifiers: const
Returns the physics layer or layers the area belongs to, as a bitmask.
int area_get_collision_layer(RID area)
Parameters
area
RID
area_get_collision_mask(RID)
Qualifiers: const
Returns the physics layer or layers the area can contact with, as a bitmask.
int area_get_collision_mask(RID area)
Parameters
area
RID
area_get_object_instance_id(RID)
Qualifiers: const
Returns the ObjectID
attached to the area. Use @GlobalScope.instance_from_id to retrieve an Object from a nonzero ObjectID
.
int area_get_object_instance_id(RID area)
Parameters
area
RID
area_get_param(RID, int)
Qualifiers: const
Returns the value of the given area parameter. See AreaParameter for the list of available parameters.
Variant area_get_param(RID area, int param)
Parameters
area_get_shape(RID, int)
Qualifiers: const
Returns the RID of the shape with the given index in the area's array of shapes.
RID area_get_shape(RID area, int shape_idx)
Parameters
area_get_shape_count(RID)
Qualifiers: const
Returns the number of shapes added to the area.
int area_get_shape_count(RID area)
Parameters
area
RID
area_get_shape_transform(RID, int)
Qualifiers: const
Returns the local transform matrix of the shape with the given index in the area's array of shapes.
Transform2D area_get_shape_transform(RID area, int shape_idx)
Parameters
area_get_space(RID)
Qualifiers: const
Returns the RID of the space assigned to the area. Returns an empty RID if no space is assigned.
RID area_get_space(RID area)
Parameters
area
RID
area_get_transform(RID)
Qualifiers: const
Returns the transform matrix of the area.
Transform2D area_get_transform(RID area)
Parameters
area
RID
area_remove_shape(RID, int)
Removes the shape with the given index from the area's array of shapes. The shape itself is not deleted, so it can continue to be used elsewhere or added back later. As a result of this operation, the area's shapes which used to have indices higher than shape_idx
will have their index decreased by one.
void area_remove_shape(RID area, int shape_idx)
Parameters
area_set_area_monitor_callback(RID, Callable)
Sets the area's area monitor callback. This callback will be called when any other (shape of an) area enters or exits (a shape of) the given area, and must take the following five parameters:
an integer
status
: either PhysicsServer2D.AREA_BODY_ADDED or PhysicsServer2D.AREA_BODY_REMOVED depending on whether the other area's shape entered or exited the area,an RID
area_rid
: the RID of the other area that entered or exited the area,an integer
instance_id
: theObjectID
attached to the other area,an integer
area_shape_idx
: the index of the shape of the other area that entered or exited the area,an integer
self_shape_idx
: the index of the shape of the area where the other area entered or exited.
By counting (or keeping track of) the shapes that enter and exit, it can be determined if an area (with all its shapes) is entering for the first time or exiting for the last time.
void area_set_area_monitor_callback(RID area, Callable callback)
Parameters
area_set_collision_layer(RID, int)
Assigns the area to one or many physics layers, via a bitmask.
void area_set_collision_layer(RID area, int layer)
Parameters
area_set_collision_mask(RID, int)
Sets which physics layers the area will monitor, via a bitmask.
void area_set_collision_mask(RID area, int mask)
Parameters
area_set_monitor_callback(RID, Callable)
Sets the area's body monitor callback. This callback will be called when any other (shape of a) body enters or exits (a shape of) the given area, and must take the following five parameters:
an integer
status
: either PhysicsServer2D.AREA_BODY_ADDED or PhysicsServer2D.AREA_BODY_REMOVED depending on whether the other body shape entered or exited the area,an RID
body_rid
: the RID of the body that entered or exited the area,an integer
instance_id
: theObjectID
attached to the body,an integer
body_shape_idx
: the index of the shape of the body that entered or exited the area,an integer
self_shape_idx
: the index of the shape of the area where the body entered or exited.
By counting (or keeping track of) the shapes that enter and exit, it can be determined if a body (with all its shapes) is entering for the first time or exiting for the last time.
void area_set_monitor_callback(RID area, Callable callback)
Parameters
area_set_monitorable(RID, bool)
Sets whether the area is monitorable or not. If monitorable
is true
, the area monitoring callback of other areas will be called when this area enters or exits them.
void area_set_monitorable(RID area, bool monitorable)
Parameters
area_set_param(RID, int, Variant)
Sets the value of the given area parameter. See AreaParameter for the list of available parameters.
void area_set_param(RID area, int param, Variant value)
Parameters
area_set_shape(RID, int, RID)
Replaces the area's shape at the given index by another shape, while not affecting the transform
and disabled
properties at the same index.
void area_set_shape(RID area, int shape_idx, RID shape)
Parameters
area_set_shape_disabled(RID, int, bool)
Sets the disabled property of the area's shape with the given index. If disabled
is true
, then the shape will not detect any other shapes entering or exiting it.
void area_set_shape_disabled(RID area, int shape_idx, bool disabled)
Parameters
area_set_shape_transform(RID, int, Transform2D)
Sets the local transform matrix of the area's shape with the given index.
void area_set_shape_transform(RID area, int shape_idx, Transform2D transform)
Parameters
area
RIDshape_idx
inttransform
Transform2D
area_set_space(RID, RID)
Adds the area to the given space, after removing the area from the previously assigned space (if any).
Note: To remove an area from a space without immediately adding it back elsewhere, use PhysicsServer2D.area_set_space(area, RID())
.
void area_set_space(RID area, RID space)
Parameters
area_set_transform(RID, Transform2D)
Sets the transform matrix of the area.
void area_set_transform(RID area, Transform2D transform)
Parameters
area
RIDtransform
Transform2D
body_add_collision_exception(RID, RID)
Adds excepted_body
to the body's list of collision exceptions, so that collisions with it are ignored.
void body_add_collision_exception(RID body, RID excepted_body)
Parameters
body_add_constant_central_force(RID, Vector2)
Adds a constant directional force to the body. The force does not affect rotation. The force remains applied over time until cleared with PhysicsServer2D.body_set_constant_force(body, Vector2(0, 0))
.
This is equivalent to using PhysicsServer2D.body_add_constant_force at the body's center of mass.
void body_add_constant_central_force(RID body, Vector2 force)
Parameters
body_add_constant_force(RID, Vector2, Vector2)
Adds a constant positioned force to the body. The force can affect rotation if position
is different from the body's center of mass. The force remains applied over time until cleared with PhysicsServer2D.body_set_constant_force(body, Vector2(0, 0))
.
position
is the offset from the body origin in global coordinates.
void body_add_constant_force(RID body, Vector2 force, Vector2 position)
Parameters
body_add_constant_torque(RID, float)
Adds a constant rotational force to the body. The force does not affect position. The force remains applied over time until cleared with PhysicsServer2D.body_set_constant_torque(body, 0)
.
void body_add_constant_torque(RID body, float torque)
Parameters
body_add_shape(RID, RID, Transform2D, bool)
Adds a shape to the area, with the given local transform. The shape (together with its transform
and disabled
properties) is added to an array of shapes, and the shapes of a body are usually referenced by their index in this array.
void body_add_shape(RID body, RID shape, Transform2D transform, bool disabled)
Parameters
body
RIDshape
RIDtransform
Transform2Ddisabled
bool
body_apply_central_force(RID, Vector2)
Applies a directional force to the body, at the body's center of mass. The force does not affect rotation. A force is time dependent and meant to be applied every physics update.
This is equivalent to using PhysicsServer2D.body_apply_force at the body's center of mass.
void body_apply_central_force(RID body, Vector2 force)
Parameters
body_apply_central_impulse(RID, Vector2)
Applies a directional impulse to the body, at the body's center of mass. The impulse does not affect 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 PhysicsServer2D.body_apply_impulse at the body's center of mass.
void body_apply_central_impulse(RID body, Vector2 impulse)
Parameters
body_apply_force(RID, Vector2, Vector2)
Applies a positioned force to the body. The force can affect rotation if position
is different from the body's center of mass. A force is time dependent and meant to be applied every physics update.
position
is the offset from the body origin in global coordinates.
void body_apply_force(RID body, Vector2 force, Vector2 position)
Parameters
body_apply_impulse(RID, Vector2, Vector2)
Applies a positioned impulse to the body. The impulse can affect rotation if position
is different from the body's center of mass.
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).
position
is the offset from the body origin in global coordinates.
void body_apply_impulse(RID body, Vector2 impulse, Vector2 position)
Parameters
body_apply_torque(RID, float)
Applies a rotational force to the body. The force does not affect position. A force is time dependent and meant to be applied every physics update.
void body_apply_torque(RID body, float torque)
Parameters
body_apply_torque_impulse(RID, float)
Applies a rotational impulse to the body. The impulse does not affect 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).
void body_apply_torque_impulse(RID body, float impulse)
Parameters
body_attach_canvas_instance_id(RID, int)
Attaches the ObjectID
of a canvas to the body. Use get_instance_id to get the ObjectID
of a CanvasLayer.
void body_attach_canvas_instance_id(RID body, int id)
Parameters
body_attach_object_instance_id(RID, int)
Attaches the ObjectID
of an Object to the body. Use get_instance_id to get the ObjectID
of a CollisionObject2D.
void body_attach_object_instance_id(RID body, int id)
Parameters
body_clear_shapes(RID)
Removes all shapes from the body. This does not delete the shapes themselves, so they can continue to be used elsewhere or added back later.
void body_clear_shapes(RID body)
Parameters
body
RID
body_create
Creates a 2D body object in the physics server, and returns the RID that identifies it. The default settings for the created area include a collision layer and mask set to 1
, and body mode set to PhysicsServer2D.BODY_MODE_RIGID.
Use PhysicsServer2D.body_add_shape to add shapes to it, use PhysicsServer2D.body_set_state to set its transform, and use PhysicsServer2D.body_set_space to add the body to a space.
RID body_create
body_get_canvas_instance_id(RID)
Qualifiers: const
Returns the ObjectID
of the canvas attached to the body. Use @GlobalScope.instance_from_id to retrieve a CanvasLayer from a nonzero ObjectID
.
int body_get_canvas_instance_id(RID body)
Parameters
body
RID
body_get_collision_layer(RID)
Qualifiers: const
Returns the physics layer or layers the body belongs to, as a bitmask.
int body_get_collision_layer(RID body)
Parameters
body
RID
body_get_collision_mask(RID)
Qualifiers: const
Returns the physics layer or layers the body can collide with, as a bitmask.
int body_get_collision_mask(RID body)
Parameters
body
RID
body_get_collision_priority(RID)
Qualifiers: const
Returns the body's collision priority. This is used in the depenetration phase of PhysicsServer2D.body_test_motion. The higher the priority is, the lower the penetration into the body will be.
float body_get_collision_priority(RID body)
Parameters
body
RID
body_get_constant_force(RID)
Qualifiers: const
Returns the body's total constant positional force applied during each physics update.
See PhysicsServer2D.body_add_constant_force and PhysicsServer2D.body_add_constant_central_force.
Vector2 body_get_constant_force(RID body)
Parameters
body
RID
body_get_constant_torque(RID)
Qualifiers: const
Returns the body's total constant rotational force applied during each physics update.
See PhysicsServer2D.body_add_constant_torque.
float body_get_constant_torque(RID body)
Parameters
body
RID
body_get_continuous_collision_detection_mode(RID)
Qualifiers: const
Returns the body's continuous collision detection mode (see CCDMode).
int body_get_continuous_collision_detection_mode(RID body)
Parameters
body
RID
body_get_direct_state(RID)
Returns the PhysicsDirectBodyState2D of the body. Returns null
if the body is destroyed or not assigned to a space.
PhysicsDirectBodyState2D body_get_direct_state(RID body)
Parameters
body
RID
body_get_max_contacts_reported(RID)
Qualifiers: const
Returns the maximum number of contacts that the body can report. See PhysicsServer2D.body_set_max_contacts_reported.
int body_get_max_contacts_reported(RID body)
Parameters
body
RID
body_get_mode(RID)
Qualifiers: const
Returns the body's mode (see BodyMode).
int body_get_mode(RID body)
Parameters
body
RID
body_get_object_instance_id(RID)
Qualifiers: const
Returns the ObjectID
attached to the body. Use @GlobalScope.instance_from_id to retrieve an Object from a nonzero ObjectID
.
int body_get_object_instance_id(RID body)
Parameters
body
RID
body_get_param(RID, int)
Qualifiers: const
Returns the value of the given body parameter. See BodyParameter for the list of available parameters.
Variant body_get_param(RID body, int param)
Parameters
body_get_shape(RID, int)
Qualifiers: const
Returns the RID of the shape with the given index in the body's array of shapes.
RID body_get_shape(RID body, int shape_idx)
Parameters
body_get_shape_count(RID)
Qualifiers: const
Returns the number of shapes added to the body.
int body_get_shape_count(RID body)
Parameters
body
RID
body_get_shape_transform(RID, int)
Qualifiers: const
Returns the local transform matrix of the shape with the given index in the area's array of shapes.
Transform2D body_get_shape_transform(RID body, int shape_idx)
Parameters
body_get_space(RID)
Qualifiers: const
Returns the RID of the space assigned to the body. Returns an empty RID if no space is assigned.
RID body_get_space(RID body)
Parameters
body
RID
body_get_state(RID, int)
Qualifiers: const
Returns the value of the given state of the body. See BodyState for the list of available states.
Variant body_get_state(RID body, int state)
Parameters
body_is_omitting_force_integration(RID)
Qualifiers: const
Returns true
if the body is omitting the standard force integration. See PhysicsServer2D.body_set_omit_force_integration.
bool body_is_omitting_force_integration(RID body)
Parameters
body
RID
body_remove_collision_exception(RID, RID)
Removes excepted_body
from the body's list of collision exceptions, so that collisions with it are no longer ignored.
void body_remove_collision_exception(RID body, RID excepted_body)
Parameters
body_remove_shape(RID, int)
Removes the shape with the given index from the body's array of shapes. The shape itself is not deleted, so it can continue to be used elsewhere or added back later. As a result of this operation, the body's shapes which used to have indices higher than shape_idx
will have their index decreased by one.
void body_remove_shape(RID body, int shape_idx)
Parameters
body_reset_mass_properties(RID)
Restores the default inertia and center of mass of the body based on its shapes. This undoes any custom values previously set using PhysicsServer2D.body_set_param.
void body_reset_mass_properties(RID body)
Parameters
body
RID
body_set_axis_velocity(RID, Vector2)
Modifies the body's linear velocity so that its projection to the axis axis_velocity.normalized()
is exactly axis_velocity.length()
. This is useful for jumping behavior.
void body_set_axis_velocity(RID body, Vector2 axis_velocity)
Parameters
body_set_collision_layer(RID, int)
Sets the physics layer or layers the body belongs to, via a bitmask.
void body_set_collision_layer(RID body, int layer)
Parameters
body_set_collision_mask(RID, int)
Sets the physics layer or layers the body can collide with, via a bitmask.
void body_set_collision_mask(RID body, int mask)
Parameters
body_set_collision_priority(RID, float)
Sets the body's collision priority. This is used in the depenetration phase of PhysicsServer2D.body_test_motion. The higher the priority is, the lower the penetration into the body will be.
void body_set_collision_priority(RID body, float priority)
Parameters
body_set_constant_force(RID, Vector2)
Sets the body's total constant positional force applied during each physics update.
See PhysicsServer2D.body_add_constant_force and PhysicsServer2D.body_add_constant_central_force.
void body_set_constant_force(RID body, Vector2 force)
Parameters
body_set_constant_torque(RID, float)
Sets the body's total constant rotational force applied during each physics update.
See PhysicsServer2D.body_add_constant_torque.
void body_set_constant_torque(RID body, float torque)
Parameters
body_set_continuous_collision_detection_mode(RID, int)
Sets the continuous collision detection mode using one of the CCDMode constants.
Continuous collision detection tries to predict where a moving body would collide in between physics updates, instead of moving it and correcting its movement if it collided.
void body_set_continuous_collision_detection_mode(RID body, int mode)
Parameters
body_set_force_integration_callback(RID, Callable, Variant)
Sets the body's custom force integration callback function to callable
. Use an empty Callable (Callable()
) to clear the custom callback.
The function callable
will be called every physics tick, before the standard force integration (see PhysicsServer2D.body_set_omit_force_integration). It can be used for example to update the body's linear and angular velocity based on contact with other bodies.
If userdata
is not null
, the function callable
must take the following two parameters:
state
: a PhysicsDirectBodyState2D used to retrieve and modify the body's state,userdata
: a Variant; its value will be theuserdata
passed into this method.
If userdata
is null
, then callable
must take only the state
parameter.
void body_set_force_integration_callback(RID body, Callable callable, Variant userdata)
Parameters
body_set_max_contacts_reported(RID, int)
Sets the maximum number of contacts that the body can report. If amount
is greater than zero, then the body will keep track of at most this many contacts with other bodies.
void body_set_max_contacts_reported(RID body, int amount)
Parameters
body_set_mode(RID, int)
Sets the body's mode. See BodyMode for the list of available modes.
void body_set_mode(RID body, int mode)
Parameters
body_set_omit_force_integration(RID, bool)
Sets whether the body omits the standard force integration. If enable
is true
, the body will not automatically use applied forces, torques, and damping to update the body's linear and angular velocity. In this case, PhysicsServer2D.body_set_force_integration_callback can be used to manually update the linear and angular velocity instead.
This method is called when the property custom_integrator is set.
void body_set_omit_force_integration(RID body, bool enable)
Parameters
body_set_param(RID, int, Variant)
Sets the value of the given body parameter. See BodyParameter for the list of available parameters.
void body_set_param(RID body, int param, Variant value)
Parameters
body_set_shape(RID, int, RID)
Replaces the body's shape at the given index by another shape, while not affecting the transform
, disabled
, and one-way collision properties at the same index.
void body_set_shape(RID body, int shape_idx, RID shape)
Parameters
body_set_shape_as_one_way_collision(RID, int, bool, float)
Sets the one-way collision properties of the body's shape with the given index. If enable
is true
, the one-way collision direction given by the shape's local upward axis body_get_shape_transform(body, shape_idx).y
will be used to ignore collisions with the shape in the opposite direction, and to ensure depenetration of kinematic bodies happens in this direction.
void body_set_shape_as_one_way_collision(RID body, int shape_idx, bool enable, float margin)
Parameters
body_set_shape_disabled(RID, int, bool)
Sets the disabled property of the body's shape with the given index. If disabled
is true
, then the shape will be ignored in all collision detection.
void body_set_shape_disabled(RID body, int shape_idx, bool disabled)
Parameters
body_set_shape_transform(RID, int, Transform2D)
Sets the local transform matrix of the body's shape with the given index.
void body_set_shape_transform(RID body, int shape_idx, Transform2D transform)
Parameters
body
RIDshape_idx
inttransform
Transform2D
body_set_space(RID, RID)
Adds the body to the given space, after removing the body from the previously assigned space (if any). If the body's mode is set to PhysicsServer2D.BODY_MODE_RIGID, then adding the body to a space will have the following additional effects:
If the parameter PhysicsServer2D.BODY_PARAM_CENTER_OF_MASS has never been set explicitly, then the value of that parameter will be recalculated based on the body's shapes.
If the parameter PhysicsServer2D.BODY_PARAM_INERTIA is set to a value
<= 0.0
, then the value of that parameter will be recalculated based on the body's shapes, mass, and center of mass.
Note: To remove a body from a space without immediately adding it back elsewhere, use PhysicsServer2D.body_set_space(body, RID())
.
void body_set_space(RID body, RID space)
Parameters
body_set_state(RID, int, Variant)
Sets the value of a body's state. See BodyState for the list of available states.
Note: The state change doesn't take effect immediately. The state will change on the next physics frame.
void body_set_state(RID body, int state, Variant value)
Parameters
body_set_state_sync_callback(RID, Callable)
Sets the body's state synchronization callback function to callable
. Use an empty Callable (Callable()
) to clear the callback.
The function callable
will be called every physics frame, assuming that the body was active during the previous physics tick, and can be used to fetch the latest state from the physics server.
The function callable
must take the following parameters:
state
: a PhysicsDirectBodyState2D, used to retrieve the body's state.
void body_set_state_sync_callback(RID body, Callable callable)
Parameters
body_test_motion(RID, PhysicsTestMotionParameters2D, PhysicsTestMotionResult2D)
Returns true
if a collision would result from moving the body along a motion vector from a given point in space. See PhysicsTestMotionParameters2D for the available motion parameters. Optionally a PhysicsTestMotionResult2D object can be passed, which will be used to store the information about the resulting collision.
bool body_test_motion(RID body, PhysicsTestMotionParameters2D parameters, PhysicsTestMotionResult2D result)
Parameters
body
RIDparameters
PhysicsTestMotionParameters2Dresult
PhysicsTestMotionResult2D
capsule_shape_create
Creates a 2D capsule shape in the physics server, and returns the RID that identifies it. Use PhysicsServer2D.shape_set_data to set the capsule's height and radius.
RID capsule_shape_create
circle_shape_create
Creates a 2D circle shape in the physics server, and returns the RID that identifies it. Use PhysicsServer2D.shape_set_data to set the circle's radius.
RID circle_shape_create
concave_polygon_shape_create
Creates a 2D concave polygon shape in the physics server, and returns the RID that identifies it. Use PhysicsServer2D.shape_set_data to set the concave polygon's segments.
RID concave_polygon_shape_create
convex_polygon_shape_create
Creates a 2D convex polygon shape in the physics server, and returns the RID that identifies it. Use PhysicsServer2D.shape_set_data to set the convex polygon's points.
RID convex_polygon_shape_create
damped_spring_joint_get_param(RID, int)
Qualifiers: const
Returns the value of the given damped spring joint parameter. See DampedSpringParam for the list of available parameters.
float damped_spring_joint_get_param(RID joint, int param)
Parameters
damped_spring_joint_set_param(RID, int, float)
Sets the value of the given damped spring joint parameter. See DampedSpringParam for the list of available parameters.
void damped_spring_joint_set_param(RID joint, int param, float value)
Parameters
free_rid(RID)
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 printed to the console.
void free_rid(RID rid)
Parameters
rid
RID
get_process_info(int)
Returns information about the current state of the 2D physics engine. See ProcessInfo for the list of available states.
int get_process_info(int process_info)
Parameters
process_info
int
joint_clear(RID)
Destroys the joint with the given RID, creates a new uninitialized joint, and makes the RID refer to this new joint.
void joint_clear(RID joint)
Parameters
joint
RID
joint_create
Creates a 2D joint in the physics server, and returns the RID that identifies it. To set the joint type, use PhysicsServer2D.joint_make_damped_spring, PhysicsServer2D.joint_make_groove or PhysicsServer2D.joint_make_pin. Use PhysicsServer2D.joint_set_param to set generic joint parameters.
RID joint_create
joint_disable_collisions_between_bodies(RID, bool)
Sets whether the bodies attached to the Joint2D will collide with each other.
void joint_disable_collisions_between_bodies(RID joint, bool disable)
Parameters
joint_get_param(RID, int)
Qualifiers: const
Returns the value of the given joint parameter. See JointParam for the list of available parameters.
float joint_get_param(RID joint, int param)
Parameters
joint_get_type(RID)
Qualifiers: const
Returns the joint's type (see JointType).
int joint_get_type(RID joint)
Parameters
joint
RID
joint_is_disabled_collisions_between_bodies(RID)
Qualifiers: const
Returns whether the bodies attached to the Joint2D will collide with each other.
bool joint_is_disabled_collisions_between_bodies(RID joint)
Parameters
joint
RID
joint_make_damped_spring(RID, Vector2, Vector2, RID, RID)
Makes the joint a damped spring joint, attached at the point anchor_a
(given in global coordinates) on the body body_a
and at the point anchor_b
(given in global coordinates) on the body body_b
. To set the parameters which are specific to the damped spring, see PhysicsServer2D.damped_spring_joint_set_param.
void joint_make_damped_spring(RID joint, Vector2 anchor_a, Vector2 anchor_b, RID body_a, RID body_b)
Parameters
joint_make_groove(RID, Vector2, Vector2, Vector2, RID, RID)
Makes the joint a groove joint.
void joint_make_groove(RID joint, Vector2 groove1_a, Vector2 groove2_a, Vector2 anchor_b, RID body_a, RID body_b)
Parameters
joint_make_pin(RID, Vector2, RID, RID)
Makes the joint a pin joint. If body_b
is an empty RID, then body_a
is pinned to the point anchor
(given in global coordinates); otherwise, body_a
is pinned to body_b
at the point anchor
(given in global coordinates). To set the parameters which are specific to the pin joint, see PhysicsServer2D.pin_joint_set_param.
void joint_make_pin(RID joint, Vector2 anchor, RID body_a, RID body_b)
Parameters
joint_set_param(RID, int, float)
Sets the value of the given joint parameter. See JointParam for the list of available parameters.
void joint_set_param(RID joint, int param, float value)
Parameters
pin_joint_get_flag(RID, int)
Qualifiers: const
Gets a pin joint flag (see PinJointFlag constants).
bool pin_joint_get_flag(RID joint, int flag)
Parameters
pin_joint_get_param(RID, int)
Qualifiers: const
Returns the value of a pin joint parameter. See PinJointParam for a list of available parameters.
float pin_joint_get_param(RID joint, int param)
Parameters
pin_joint_set_flag(RID, int, bool)
Sets a pin joint flag (see PinJointFlag constants).
void pin_joint_set_flag(RID joint, int flag, bool enabled)
Parameters
pin_joint_set_param(RID, int, float)
Sets a pin joint parameter. See PinJointParam for a list of available parameters.
void pin_joint_set_param(RID joint, int param, float value)
Parameters
rectangle_shape_create
Creates a 2D rectangle shape in the physics server, and returns the RID that identifies it. Use PhysicsServer2D.shape_set_data to set the rectangle's half-extents.
RID rectangle_shape_create
segment_shape_create
Creates a 2D segment shape in the physics server, and returns the RID that identifies it. Use PhysicsServer2D.shape_set_data to set the segment's start and end points.
RID segment_shape_create
separation_ray_shape_create
Creates a 2D separation ray shape in the physics server, and returns the RID that identifies it. Use PhysicsServer2D.shape_set_data to set the shape's length
and slide_on_slope
properties.
RID separation_ray_shape_create
set_active(bool)
Activates or deactivates the 2D physics server. If active
is false
, then the physics server will not do anything in its physics step.
void set_active(bool active)
Parameters
active
bool
shape_get_data(RID)
Qualifiers: const
Returns the shape data that defines the configuration of the shape, such as the half-extents of a rectangle or the segments of a concave shape. See PhysicsServer2D.shape_set_data for the precise format of this data in each case.
Variant shape_get_data(RID shape)
Parameters
shape
RID
shape_get_type(RID)
Qualifiers: const
Returns the shape's type (see ShapeType).
int shape_get_type(RID shape)
Parameters
shape
RID
shape_set_data(RID, Variant)
Sets the shape data that defines the configuration of the shape. The data
to be passed depends on the shape's type (see PhysicsServer2D.shape_get_type):
PhysicsServer2D.SHAPE_WORLD_BOUNDARY: an array of length two containing a Vector2
normal
direction and a float distanced
,PhysicsServer2D.SHAPE_SEPARATION_RAY: a dictionary containing the key
length
with a float value and the keyslide_on_slope
with a bool value,PhysicsServer2D.SHAPE_SEGMENT: a Rect2
rect
containing the first point of the segment inrect.position
and the second point of the segment inrect.size
,PhysicsServer2D.SHAPE_CIRCLE: a float
radius
,PhysicsServer2D.SHAPE_RECTANGLE: a Vector2
half_extents
,PhysicsServer2D.SHAPE_CAPSULE: an array of length two (or a Vector2) containing a float
height
and a floatradius
,PhysicsServer2D.SHAPE_CONVEX_POLYGON: either a PackedVector2Array of points defining a convex polygon in counterclockwise order (the clockwise outward normal of each segment formed by consecutive points is calculated internally), or a PackedFloat32Array of length divisible by four so that every 4-tuple of floats contains the coordinates of a point followed by the coordinates of the clockwise outward normal vector to the segment between the current point and the next point,
PhysicsServer2D.SHAPE_CONCAVE_POLYGON: a PackedVector2Array of length divisible by two (each pair of points forms one segment).
Warning: In the case of PhysicsServer2D.SHAPE_CONVEX_POLYGON, this method does not check if the points supplied actually form a convex polygon (unlike the polygon property).
void shape_set_data(RID shape, Variant data)
Parameters
space_create
Creates a 2D space in the physics server, and returns the RID that identifies it. A space contains bodies and areas, and controls the stepping of the physics simulation of the objects in it.
RID space_create
space_get_direct_state(RID)
Returns the state of a space, a PhysicsDirectSpaceState2D. This object can be used for collision/intersection queries.
PhysicsDirectSpaceState2D space_get_direct_state(RID space)
Parameters
space
RID
space_get_param(RID, int)
Qualifiers: const
Returns the value of the given space parameter. See SpaceParameter for the list of available parameters.
float space_get_param(RID space, int param)
Parameters
space_is_active(RID)
Qualifiers: const
Returns true
if the space is active.
bool space_is_active(RID space)
Parameters
space
RID
space_set_active(RID, bool)
Activates or deactivates the space. If active
is false
, then the physics server will not do anything with this space in its physics step.
void space_set_active(RID space, bool active)
Parameters
space_set_param(RID, int, float)
Sets the value of the given space parameter. See SpaceParameter for the list of available parameters.
void space_set_param(RID space, int param, float value)
Parameters
world_boundary_shape_create
Creates a 2D world boundary shape in the physics server, and returns the RID that identifies it. Use PhysicsServer2D.shape_set_data to set the shape's normal direction and distance properties.
RID world_boundary_shape_create