Struct PhysicsServer2D
pub struct PhysicsServer2D { /* private fields */ }Expand description
Godot class PhysicsServer2D.
Inherits Object.
Related symbols:
physics_server_2d: sidecar module with related enum/flag types
See also Godot docs for PhysicsServer2D.
§Singleton
This class is a singleton. You can get the one instance using Singleton::singleton().
§Final class
This class is final, meaning you cannot inherit from it, and it comes without I* interface trait. It is still possible that other Godot classes inherit from it, but that is limited to the engine itself.
§Godot docs
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.
Implementations§
§impl PhysicsServer2D
impl PhysicsServer2D
pub fn world_boundary_shape_create(&mut self) -> Rid
pub fn world_boundary_shape_create(&mut self) -> Rid
Creates a 2D world boundary shape in the physics server, and returns the RID that identifies it. Use shape_set_data to set the shape’s normal direction and distance properties.
pub fn separation_ray_shape_create(&mut self) -> Rid
pub fn separation_ray_shape_create(&mut self) -> Rid
Creates a 2D separation ray shape in the physics server, and returns the RID that identifies it. Use shape_set_data to set the shape’s length and slide_on_slope properties.
pub fn segment_shape_create(&mut self) -> Rid
pub fn segment_shape_create(&mut self) -> Rid
Creates a 2D segment shape in the physics server, and returns the RID that identifies it. Use shape_set_data to set the segment’s start and end points.
pub fn circle_shape_create(&mut self) -> Rid
pub fn circle_shape_create(&mut self) -> Rid
Creates a 2D circle shape in the physics server, and returns the RID that identifies it. Use shape_set_data to set the circle’s radius.
pub fn rectangle_shape_create(&mut self) -> Rid
pub fn rectangle_shape_create(&mut self) -> Rid
Creates a 2D rectangle shape in the physics server, and returns the RID that identifies it. Use shape_set_data to set the rectangle’s half-extents.
pub fn capsule_shape_create(&mut self) -> Rid
pub fn capsule_shape_create(&mut self) -> Rid
Creates a 2D capsule shape in the physics server, and returns the RID that identifies it. Use shape_set_data to set the capsule’s height and radius.
pub fn convex_polygon_shape_create(&mut self) -> Rid
pub fn convex_polygon_shape_create(&mut self) -> Rid
Creates a 2D convex polygon shape in the physics server, and returns the RID that identifies it. Use shape_set_data to set the convex polygon’s points.
pub fn concave_polygon_shape_create(&mut self) -> Rid
pub fn concave_polygon_shape_create(&mut self) -> Rid
Creates a 2D concave polygon shape in the physics server, and returns the RID that identifies it. Use shape_set_data to set the concave polygon’s segments.
pub fn shape_set_data(&mut self, shape: Rid, data: &Variant)
pub fn shape_set_data(&mut self, shape: Rid, data: &Variant)
Sets the shape data that defines the configuration of the shape. The data to be passed depends on the shape’s type (see shape_get_type):
-
ShapeType::WORLD_BOUNDARY: an array of length two containing aVector2normaldirection and afloatdistanced, -
ShapeType::SEPARATION_RAY: a dictionary containing the keylengthwith afloatvalue and the keyslide_on_slopewith aboolvalue, -
ShapeType::SEGMENT: aRect2rectcontaining the first point of the segment inrect.positionand the second point of the segment inrect.size, -
ShapeType::CIRCLE: afloatradius, -
ShapeType::RECTANGLE: aVector2half_extents, -
ShapeType::CAPSULE: an array of length two (or aVector2) containing afloatheightand afloatradius, -
ShapeType::CONVEX_POLYGON: either aPackedVector2Arrayof points defining a convex polygon in counterclockwise order (the clockwise outward normal of each segment formed by consecutive points is calculated internally), or aPackedFloat32Arrayof length divisible by four so that every 4-tuple offloats 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, -
ShapeType::CONCAVE_POLYGON: aPackedVector2Arrayof length divisible by two (each pair of points forms one segment).
Warning: In the case of ShapeType::CONVEX_POLYGON, this method does not check if the points supplied actually form a convex polygon (unlike the [member CollisionPolygon2D.polygon] property).
pub fn shape_get_type(&self, shape: Rid) -> ShapeType
pub fn shape_get_type(&self, shape: Rid) -> ShapeType
Returns the shape’s type.
pub fn shape_get_data(&self, shape: Rid) -> Variant
pub fn shape_get_data(&self, shape: Rid) -> Variant
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 shape_set_data for the precise format of this data in each case.
pub fn space_create(&mut self) -> Rid
pub fn space_create(&mut self) -> Rid
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.
pub fn space_set_active(&mut self, space: Rid, active: bool)
pub fn space_set_active(&mut self, space: Rid, active: 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.
pub fn space_is_active(&self, space: Rid) -> bool
pub fn space_is_active(&self, space: Rid) -> bool
Returns true if the space is active.
pub fn space_set_param(&mut self, space: Rid, param: SpaceParameter, value: f32)
pub fn space_set_param(&mut self, space: Rid, param: SpaceParameter, value: f32)
Sets the value of the given space parameter.
pub fn space_get_param(&self, space: Rid, param: SpaceParameter) -> f32
pub fn space_get_param(&self, space: Rid, param: SpaceParameter) -> f32
Returns the value of the given space parameter.
pub fn space_get_direct_state(
&mut self,
space: Rid,
) -> Option<Gd<PhysicsDirectSpaceState2D>>
pub fn space_get_direct_state( &mut self, space: Rid, ) -> Option<Gd<PhysicsDirectSpaceState2D>>
Returns the state of a space, a PhysicsDirectSpaceState2D. This object can be used for collision/intersection queries.
pub fn area_create(&mut self) -> Rid
pub fn area_create(&mut self) -> Rid
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 area_add_shape to add shapes to it, use area_set_transform to set its transform, and use area_set_space to add the area to a space. If you want the area to be detectable use area_set_monitorable.
pub fn area_set_space(&mut self, area: Rid, space: Rid)
pub fn area_set_space(&mut self, area: Rid, space: 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()).
pub fn area_get_space(&self, area: Rid) -> Rid
pub fn area_get_space(&self, area: Rid) -> Rid
pub fn area_add_shape(&mut self, area: Rid, shape: Rid)
pub fn area_add_shape(&mut self, area: Rid, shape: Rid)
To set the default parameters, use area_add_shape_ex and its builder methods. See the book for detailed usage instructions.
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.
pub fn area_add_shape_ex<'ex>(
&'ex mut self,
area: Rid,
shape: Rid,
) -> ExAreaAddShape<'ex>
pub fn area_add_shape_ex<'ex>( &'ex mut self, area: Rid, shape: Rid, ) -> ExAreaAddShape<'ex>
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.
pub fn area_set_shape(&mut self, area: Rid, shape_idx: i32, shape: Rid)
pub fn area_set_shape(&mut self, area: Rid, shape_idx: i32, shape: 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.
pub fn area_set_shape_transform(
&mut self,
area: Rid,
shape_idx: i32,
transform: Transform2D,
)
pub fn area_set_shape_transform( &mut self, area: Rid, shape_idx: i32, transform: Transform2D, )
Sets the local transform matrix of the area’s shape with the given index.
pub fn area_set_shape_disabled(
&mut self,
area: Rid,
shape_idx: i32,
disabled: bool,
)
pub fn area_set_shape_disabled( &mut self, area: Rid, shape_idx: i32, disabled: 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.
pub fn area_get_shape_count(&self, area: Rid) -> i32
pub fn area_get_shape_count(&self, area: Rid) -> i32
Returns the number of shapes added to the area.
pub fn area_get_shape(&self, area: Rid, shape_idx: i32) -> Rid
pub fn area_get_shape(&self, area: Rid, shape_idx: i32) -> Rid
Returns the RID of the shape with the given index in the area’s array of shapes.
pub fn area_get_shape_transform(&self, area: Rid, shape_idx: i32) -> Transform2D
pub fn area_get_shape_transform(&self, area: Rid, shape_idx: i32) -> Transform2D
Returns the local transform matrix of the shape with the given index in the area’s array of shapes.
pub fn area_remove_shape(&mut self, area: Rid, shape_idx: i32)
pub fn area_remove_shape(&mut self, area: Rid, shape_idx: i32)
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.
pub fn area_clear_shapes(&mut self, area: Rid)
pub fn area_clear_shapes(&mut self, area: 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.
pub fn area_set_collision_layer(&mut self, area: Rid, layer: u32)
pub fn area_set_collision_layer(&mut self, area: Rid, layer: u32)
Assigns the area to one or many physics layers, via a bitmask.
pub fn area_get_collision_layer(&self, area: Rid) -> u32
pub fn area_get_collision_layer(&self, area: Rid) -> u32
Returns the physics layer or layers the area belongs to, as a bitmask.
pub fn area_set_collision_mask(&mut self, area: Rid, mask: u32)
pub fn area_set_collision_mask(&mut self, area: Rid, mask: u32)
Sets which physics layers the area will monitor, via a bitmask.
pub fn area_get_collision_mask(&self, area: Rid) -> u32
pub fn area_get_collision_mask(&self, area: Rid) -> u32
Returns the physics layer or layers the area can contact with, as a bitmask.
pub fn area_set_param(
&mut self,
area: Rid,
param: AreaParameter,
value: &Variant,
)
pub fn area_set_param( &mut self, area: Rid, param: AreaParameter, value: &Variant, )
Sets the value of the given area parameter.
pub fn area_set_transform(&mut self, area: Rid, transform: Transform2D)
pub fn area_set_transform(&mut self, area: Rid, transform: Transform2D)
Sets the transform matrix of the area.
pub fn area_get_param(&self, area: Rid, param: AreaParameter) -> Variant
pub fn area_get_param(&self, area: Rid, param: AreaParameter) -> Variant
Returns the value of the given area parameter.
pub fn area_get_transform(&self, area: Rid) -> Transform2D
pub fn area_get_transform(&self, area: Rid) -> Transform2D
Returns the transform matrix of the area.
pub fn area_attach_object_instance_id(&mut self, area: Rid, id: u64)
pub fn area_attach_object_instance_id(&mut self, area: Rid, id: u64)
Attaches the ObjectID of an Object to the area. Use instance_id to get the ObjectID of a CollisionObject2D.
pub fn area_get_object_instance_id(&self, area: Rid) -> u64
pub fn area_get_object_instance_id(&self, area: Rid) -> u64
Returns the ObjectID attached to the area. Use from_instance_id to retrieve an Object from a nonzero ObjectID.
pub fn area_attach_canvas_instance_id(&mut self, area: Rid, id: u64)
pub fn area_attach_canvas_instance_id(&mut self, area: Rid, id: u64)
Attaches the ObjectID of a canvas to the area. Use instance_id to get the ObjectID of a CanvasLayer.
pub fn area_get_canvas_instance_id(&self, area: Rid) -> u64
pub fn area_get_canvas_instance_id(&self, area: Rid) -> u64
Returns the ObjectID of the canvas attached to the area. Use from_instance_id to retrieve a CanvasLayer from a nonzero ObjectID.
pub fn area_set_monitor_callback(&mut self, area: Rid, callback: &Callable)
pub fn area_set_monitor_callback(&mut self, area: Rid, callback: &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: eitherAreaBodyStatus::ADDEDorAreaBodyStatus::REMOVEDdepending on whether the other body shape entered or exited the area, -
an
RIDbody_rid: theRIDof the body that entered or exited the area, -
an integer
instance_id: theObjectIDattached 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.
pub fn area_set_area_monitor_callback(&mut self, area: Rid, callback: &Callable)
pub fn area_set_area_monitor_callback(&mut self, area: Rid, callback: &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: eitherAreaBodyStatus::ADDEDorAreaBodyStatus::REMOVEDdepending on whether the other area’s shape entered or exited the area, -
an
RIDarea_rid: theRIDof the other area that entered or exited the area, -
an integer
instance_id: theObjectIDattached 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.
pub fn area_set_monitorable(&mut self, area: Rid, monitorable: bool)
pub fn area_set_monitorable(&mut self, area: Rid, monitorable: 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.
pub fn body_create(&mut self) -> Rid
pub fn body_create(&mut self) -> Rid
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 BodyMode::RIGID.
Use body_add_shape to add shapes to it, use body_set_state to set its transform, and use body_set_space to add the body to a space.
pub fn body_set_space(&mut self, body: Rid, space: Rid)
pub fn body_set_space(&mut self, body: Rid, space: 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 BodyMode::RIGID, then adding the body to a space will have the following additional effects:
-
If the parameter
BodyParameter::CENTER_OF_MASShas never been set explicitly, then the value of that parameter will be recalculated based on the body’s shapes. -
If the parameter
BodyParameter::INERTIAis 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()).
pub fn body_get_space(&self, body: Rid) -> Rid
pub fn body_get_space(&self, body: Rid) -> Rid
pub fn body_set_mode(&mut self, body: Rid, mode: BodyMode)
pub fn body_set_mode(&mut self, body: Rid, mode: BodyMode)
Sets the body’s mode.
pub fn body_get_mode(&self, body: Rid) -> BodyMode
pub fn body_get_mode(&self, body: Rid) -> BodyMode
Returns the body’s mode.
pub fn body_add_shape(&mut self, body: Rid, shape: Rid)
pub fn body_add_shape(&mut self, body: Rid, shape: Rid)
To set the default parameters, use body_add_shape_ex and its builder methods. See the book for detailed usage instructions.
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.
pub fn body_add_shape_ex<'ex>(
&'ex mut self,
body: Rid,
shape: Rid,
) -> ExBodyAddShape<'ex>
pub fn body_add_shape_ex<'ex>( &'ex mut self, body: Rid, shape: Rid, ) -> ExBodyAddShape<'ex>
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.
pub fn body_set_shape(&mut self, body: Rid, shape_idx: i32, shape: Rid)
pub fn body_set_shape(&mut self, body: Rid, shape_idx: i32, shape: 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.
pub fn body_set_shape_transform(
&mut self,
body: Rid,
shape_idx: i32,
transform: Transform2D,
)
pub fn body_set_shape_transform( &mut self, body: Rid, shape_idx: i32, transform: Transform2D, )
Sets the local transform matrix of the body’s shape with the given index.
pub fn body_get_shape_count(&self, body: Rid) -> i32
pub fn body_get_shape_count(&self, body: Rid) -> i32
Returns the number of shapes added to the body.
pub fn body_get_shape(&self, body: Rid, shape_idx: i32) -> Rid
pub fn body_get_shape(&self, body: Rid, shape_idx: i32) -> Rid
Returns the RID of the shape with the given index in the body’s array of shapes.
pub fn body_get_shape_transform(&self, body: Rid, shape_idx: i32) -> Transform2D
pub fn body_get_shape_transform(&self, body: Rid, shape_idx: i32) -> Transform2D
Returns the local transform matrix of the shape with the given index in the area’s array of shapes.
pub fn body_remove_shape(&mut self, body: Rid, shape_idx: i32)
pub fn body_remove_shape(&mut self, body: Rid, shape_idx: i32)
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.
pub fn body_clear_shapes(&mut self, body: Rid)
pub fn body_clear_shapes(&mut self, body: 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.
pub fn body_set_shape_disabled(
&mut self,
body: Rid,
shape_idx: i32,
disabled: bool,
)
pub fn body_set_shape_disabled( &mut self, body: Rid, shape_idx: i32, disabled: 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.
pub fn body_set_shape_as_one_way_collision(
&mut self,
body: Rid,
shape_idx: i32,
enable: bool,
margin: f32,
)
pub fn body_set_shape_as_one_way_collision( &mut self, body: Rid, shape_idx: i32, enable: bool, margin: f32, )
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.
pub fn body_attach_object_instance_id(&mut self, body: Rid, id: u64)
pub fn body_attach_object_instance_id(&mut self, body: Rid, id: u64)
Attaches the ObjectID of an Object to the body. Use instance_id to get the ObjectID of a CollisionObject2D.
pub fn body_get_object_instance_id(&self, body: Rid) -> u64
pub fn body_get_object_instance_id(&self, body: Rid) -> u64
Returns the ObjectID attached to the body. Use from_instance_id to retrieve an Object from a nonzero ObjectID.
pub fn body_attach_canvas_instance_id(&mut self, body: Rid, id: u64)
pub fn body_attach_canvas_instance_id(&mut self, body: Rid, id: u64)
Attaches the ObjectID of a canvas to the body. Use instance_id to get the ObjectID of a CanvasLayer.
pub fn body_get_canvas_instance_id(&self, body: Rid) -> u64
pub fn body_get_canvas_instance_id(&self, body: Rid) -> u64
Returns the ObjectID of the canvas attached to the body. Use from_instance_id to retrieve a CanvasLayer from a nonzero ObjectID.
pub fn body_set_continuous_collision_detection_mode(
&mut self,
body: Rid,
mode: CcdMode,
)
pub fn body_set_continuous_collision_detection_mode( &mut self, body: Rid, mode: CcdMode, )
Sets the continuous collision detection mode.
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.
pub fn body_get_continuous_collision_detection_mode(&self, body: Rid) -> CcdMode
pub fn body_get_continuous_collision_detection_mode(&self, body: Rid) -> CcdMode
Returns the body’s continuous collision detection mode.
pub fn body_set_collision_layer(&mut self, body: Rid, layer: u32)
pub fn body_set_collision_layer(&mut self, body: Rid, layer: u32)
Sets the physics layer or layers the body belongs to, via a bitmask.
pub fn body_get_collision_layer(&self, body: Rid) -> u32
pub fn body_get_collision_layer(&self, body: Rid) -> u32
Returns the physics layer or layers the body belongs to, as a bitmask.
pub fn body_set_collision_mask(&mut self, body: Rid, mask: u32)
pub fn body_set_collision_mask(&mut self, body: Rid, mask: u32)
Sets the physics layer or layers the body can collide with, via a bitmask.
pub fn body_get_collision_mask(&self, body: Rid) -> u32
pub fn body_get_collision_mask(&self, body: Rid) -> u32
Returns the physics layer or layers the body can collide with, as a bitmask.
pub fn body_set_collision_priority(&mut self, body: Rid, priority: f32)
pub fn body_set_collision_priority(&mut self, body: Rid, priority: f32)
Sets the body’s collision priority. This is used in the depenetration phase of body_test_motion. The higher the priority is, the lower the penetration into the body will be.
pub fn body_get_collision_priority(&self, body: Rid) -> f32
pub fn body_get_collision_priority(&self, body: Rid) -> f32
Returns the body’s collision priority. This is used in the depenetration phase of body_test_motion. The higher the priority is, the lower the penetration into the body will be.
pub fn body_set_param(
&mut self,
body: Rid,
param: BodyParameter,
value: &Variant,
)
pub fn body_set_param( &mut self, body: Rid, param: BodyParameter, value: &Variant, )
Sets the value of the given body parameter.
pub fn body_get_param(&self, body: Rid, param: BodyParameter) -> Variant
pub fn body_get_param(&self, body: Rid, param: BodyParameter) -> Variant
Returns the value of the given body parameter.
pub fn body_reset_mass_properties(&mut self, body: Rid)
pub fn body_reset_mass_properties(&mut self, body: Rid)
Restores the default inertia and center of mass of the body based on its shapes. This undoes any custom values previously set using body_set_param.
pub fn body_set_state(&mut self, body: Rid, state: BodyState, value: &Variant)
pub fn body_set_state(&mut self, body: Rid, state: BodyState, value: &Variant)
Sets the value of a body’s state.
Note: The state change doesn’t take effect immediately. The state will change on the next physics frame.
pub fn body_get_state(&self, body: Rid, state: BodyState) -> Variant
pub fn body_get_state(&self, body: Rid, state: BodyState) -> Variant
Returns the value of the given state of the body.
pub fn body_apply_central_impulse(&mut self, body: Rid, impulse: Vector2)
pub fn body_apply_central_impulse(&mut self, body: Rid, impulse: 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 body_apply_impulse at the body’s center of mass.
pub fn body_apply_torque_impulse(&mut self, body: Rid, impulse: f32)
pub fn body_apply_torque_impulse(&mut self, body: Rid, impulse: f32)
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).
pub fn body_apply_impulse(&mut self, body: Rid, impulse: Vector2)
pub fn body_apply_impulse(&mut self, body: Rid, impulse: Vector2)
To set the default parameters, use body_apply_impulse_ex and its builder methods. See the book for detailed usage instructions.
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.
pub fn body_apply_impulse_ex<'ex>(
&'ex mut self,
body: Rid,
impulse: Vector2,
) -> ExBodyApplyImpulse<'ex>
pub fn body_apply_impulse_ex<'ex>( &'ex mut self, body: Rid, impulse: Vector2, ) -> ExBodyApplyImpulse<'ex>
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.
pub fn body_apply_central_force(&mut self, body: Rid, force: Vector2)
pub fn body_apply_central_force(&mut self, body: Rid, force: 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 body_apply_force at the body’s center of mass.
pub fn body_apply_force(&mut self, body: Rid, force: Vector2)
pub fn body_apply_force(&mut self, body: Rid, force: Vector2)
To set the default parameters, use body_apply_force_ex and its builder methods. See the book for detailed usage instructions.
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.
pub fn body_apply_force_ex<'ex>(
&'ex mut self,
body: Rid,
force: Vector2,
) -> ExBodyApplyForce<'ex>
pub fn body_apply_force_ex<'ex>( &'ex mut self, body: Rid, force: Vector2, ) -> ExBodyApplyForce<'ex>
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.
pub fn body_apply_torque(&mut self, body: Rid, torque: f32)
pub fn body_apply_torque(&mut self, body: Rid, torque: f32)
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.
pub fn body_add_constant_central_force(&mut self, body: Rid, force: Vector2)
pub fn body_add_constant_central_force(&mut self, body: Rid, force: 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 body_add_constant_force at the body’s center of mass.
pub fn body_add_constant_force(&mut self, body: Rid, force: Vector2)
pub fn body_add_constant_force(&mut self, body: Rid, force: Vector2)
To set the default parameters, use body_add_constant_force_ex and its builder methods. See the book for detailed usage instructions.
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.
pub fn body_add_constant_force_ex<'ex>(
&'ex mut self,
body: Rid,
force: Vector2,
) -> ExBodyAddConstantForce<'ex>
pub fn body_add_constant_force_ex<'ex>( &'ex mut self, body: Rid, force: Vector2, ) -> ExBodyAddConstantForce<'ex>
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.
pub fn body_add_constant_torque(&mut self, body: Rid, torque: f32)
pub fn body_add_constant_torque(&mut self, body: Rid, torque: f32)
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).
pub fn body_set_constant_force(&mut self, body: Rid, force: Vector2)
pub fn body_set_constant_force(&mut self, body: Rid, force: Vector2)
Sets the body’s total constant positional force applied during each physics update.
See body_add_constant_force and body_add_constant_central_force.
pub fn body_get_constant_force(&self, body: Rid) -> Vector2
pub fn body_get_constant_force(&self, body: Rid) -> Vector2
Returns the body’s total constant positional force applied during each physics update.
See body_add_constant_force and body_add_constant_central_force.
pub fn body_set_constant_torque(&mut self, body: Rid, torque: f32)
pub fn body_set_constant_torque(&mut self, body: Rid, torque: f32)
Sets the body’s total constant rotational force applied during each physics update.
pub fn body_get_constant_torque(&self, body: Rid) -> f32
pub fn body_get_constant_torque(&self, body: Rid) -> f32
Returns the body’s total constant rotational force applied during each physics update.
pub fn body_set_axis_velocity(&mut self, body: Rid, axis_velocity: Vector2)
pub fn body_set_axis_velocity(&mut self, body: Rid, axis_velocity: 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.
pub fn body_add_collision_exception(&mut self, body: Rid, excepted_body: Rid)
pub fn body_add_collision_exception(&mut self, body: Rid, excepted_body: Rid)
Adds excepted_body to the body’s list of collision exceptions, so that collisions with it are ignored.
pub fn body_remove_collision_exception(&mut self, body: Rid, excepted_body: Rid)
pub fn body_remove_collision_exception(&mut self, body: Rid, excepted_body: Rid)
Removes excepted_body from the body’s list of collision exceptions, so that collisions with it are no longer ignored.
pub fn body_set_max_contacts_reported(&mut self, body: Rid, amount: i32)
pub fn body_set_max_contacts_reported(&mut self, body: Rid, amount: i32)
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.
pub fn body_get_max_contacts_reported(&self, body: Rid) -> i32
pub fn body_get_max_contacts_reported(&self, body: Rid) -> i32
Returns the maximum number of contacts that the body can report. See body_set_max_contacts_reported.
pub fn body_set_omit_force_integration(&mut self, body: Rid, enable: bool)
pub fn body_set_omit_force_integration(&mut self, body: Rid, enable: 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, body_set_force_integration_callback can be used to manually update the linear and angular velocity instead.
This method is called when the property [member RigidBody2D.custom_integrator] is set.
pub fn body_is_omitting_force_integration(&self, body: Rid) -> bool
pub fn body_is_omitting_force_integration(&self, body: Rid) -> bool
Returns true if the body is omitting the standard force integration. See body_set_omit_force_integration.
pub fn body_set_state_sync_callback(&mut self, body: Rid, callable: &Callable)
pub fn body_set_state_sync_callback(&mut self, body: Rid, callable: &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: aPhysicsDirectBodyState2D, used to retrieve the body’s state.
pub fn body_set_force_integration_callback(
&mut self,
body: Rid,
callable: &Callable,
)
pub fn body_set_force_integration_callback( &mut self, body: Rid, callable: &Callable, )
To set the default parameters, use body_set_force_integration_callback_ex and its builder methods. See the book for detailed usage instructions.
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 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: aPhysicsDirectBodyState2Dused to retrieve and modify the body’s state, -
userdata: aVariant; its value will be theuserdatapassed into this method.
If userdata is null, then callable must take only the state parameter.
pub fn body_set_force_integration_callback_ex<'ex>(
&'ex mut self,
body: Rid,
callable: &'ex Callable,
) -> ExBodySetForceIntegrationCallback<'ex>
pub fn body_set_force_integration_callback_ex<'ex>( &'ex mut self, body: Rid, callable: &'ex Callable, ) -> ExBodySetForceIntegrationCallback<'ex>
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 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: aPhysicsDirectBodyState2Dused to retrieve and modify the body’s state, -
userdata: aVariant; its value will be theuserdatapassed into this method.
If userdata is null, then callable must take only the state parameter.
pub fn body_test_motion(
&mut self,
body: Rid,
parameters: impl AsArg<Gd<PhysicsTestMotionParameters2D>>,
) -> bool
pub fn body_test_motion( &mut self, body: Rid, parameters: impl AsArg<Gd<PhysicsTestMotionParameters2D>>, ) -> bool
To set the default parameters, use body_test_motion_ex and its builder methods. See the book for detailed usage instructions.
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.
pub fn body_test_motion_ex<'ex>(
&'ex mut self,
body: Rid,
parameters: impl AsArg<Gd<PhysicsTestMotionParameters2D>> + 'ex,
) -> ExBodyTestMotion<'ex>
pub fn body_test_motion_ex<'ex>( &'ex mut self, body: Rid, parameters: impl AsArg<Gd<PhysicsTestMotionParameters2D>> + 'ex, ) -> ExBodyTestMotion<'ex>
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.
pub fn body_get_direct_state(
&mut self,
body: Rid,
) -> Option<Gd<PhysicsDirectBodyState2D>>
pub fn body_get_direct_state( &mut self, body: Rid, ) -> Option<Gd<PhysicsDirectBodyState2D>>
Returns the PhysicsDirectBodyState2D of the body. Returns null if the body is destroyed or not assigned to a space.
pub fn joint_create(&mut self) -> Rid
pub fn joint_create(&mut self) -> Rid
Creates a 2D joint in the physics server, and returns the RID that identifies it. To set the joint type, use joint_make_damped_spring, joint_make_groove or joint_make_pin. Use joint_set_param to set generic joint parameters.
pub fn joint_clear(&mut self, joint: Rid)
pub fn joint_clear(&mut self, joint: Rid)
pub fn joint_set_param(&mut self, joint: Rid, param: JointParam, value: f32)
pub fn joint_set_param(&mut self, joint: Rid, param: JointParam, value: f32)
Sets the value of the given joint parameter.
pub fn joint_get_param(&self, joint: Rid, param: JointParam) -> f32
pub fn joint_get_param(&self, joint: Rid, param: JointParam) -> f32
Returns the value of the given joint parameter.
pub fn joint_disable_collisions_between_bodies(
&mut self,
joint: Rid,
disable: bool,
)
pub fn joint_disable_collisions_between_bodies( &mut self, joint: Rid, disable: bool, )
Sets whether the bodies attached to the Joint2D will collide with each other.
pub fn joint_is_disabled_collisions_between_bodies(&self, joint: Rid) -> bool
pub fn joint_is_disabled_collisions_between_bodies(&self, joint: Rid) -> bool
Returns whether the bodies attached to the Joint2D will collide with each other.
pub fn joint_make_pin(&mut self, joint: Rid, anchor: Vector2, body_a: Rid)
pub fn joint_make_pin(&mut self, joint: Rid, anchor: Vector2, body_a: Rid)
To set the default parameters, use joint_make_pin_ex and its builder methods. See the book for detailed usage instructions.
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 pin_joint_set_param.
pub fn joint_make_pin_ex<'ex>(
&'ex mut self,
joint: Rid,
anchor: Vector2,
body_a: Rid,
) -> ExJointMakePin<'ex>
pub fn joint_make_pin_ex<'ex>( &'ex mut self, joint: Rid, anchor: Vector2, body_a: Rid, ) -> ExJointMakePin<'ex>
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 pin_joint_set_param.
pub fn joint_make_groove(
&mut self,
joint: Rid,
groove1_a: Vector2,
groove2_a: Vector2,
anchor_b: Vector2,
)
pub fn joint_make_groove( &mut self, joint: Rid, groove1_a: Vector2, groove2_a: Vector2, anchor_b: Vector2, )
To set the default parameters, use joint_make_groove_ex and its builder methods. See the book for detailed usage instructions.
Makes the joint a groove joint.
pub fn joint_make_groove_ex<'ex>(
&'ex mut self,
joint: Rid,
groove1_a: Vector2,
groove2_a: Vector2,
anchor_b: Vector2,
) -> ExJointMakeGroove<'ex>
pub fn joint_make_groove_ex<'ex>( &'ex mut self, joint: Rid, groove1_a: Vector2, groove2_a: Vector2, anchor_b: Vector2, ) -> ExJointMakeGroove<'ex>
Makes the joint a groove joint.
pub fn joint_make_damped_spring(
&mut self,
joint: Rid,
anchor_a: Vector2,
anchor_b: Vector2,
body_a: Rid,
)
pub fn joint_make_damped_spring( &mut self, joint: Rid, anchor_a: Vector2, anchor_b: Vector2, body_a: Rid, )
To set the default parameters, use joint_make_damped_spring_ex and its builder methods. See the book for detailed usage instructions.
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 damped_spring_joint_set_param.
pub fn joint_make_damped_spring_ex<'ex>(
&'ex mut self,
joint: Rid,
anchor_a: Vector2,
anchor_b: Vector2,
body_a: Rid,
) -> ExJointMakeDampedSpring<'ex>
pub fn joint_make_damped_spring_ex<'ex>( &'ex mut self, joint: Rid, anchor_a: Vector2, anchor_b: Vector2, body_a: Rid, ) -> ExJointMakeDampedSpring<'ex>
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 damped_spring_joint_set_param.
pub fn pin_joint_set_flag(
&mut self,
joint: Rid,
flag: PinJointFlag,
enabled: bool,
)
pub fn pin_joint_set_flag( &mut self, joint: Rid, flag: PinJointFlag, enabled: bool, )
Sets a pin joint flag.
pub fn pin_joint_get_flag(&self, joint: Rid, flag: PinJointFlag) -> bool
pub fn pin_joint_get_flag(&self, joint: Rid, flag: PinJointFlag) -> bool
Gets a pin joint flag.
pub fn pin_joint_set_param(
&mut self,
joint: Rid,
param: PinJointParam,
value: f32,
)
pub fn pin_joint_set_param( &mut self, joint: Rid, param: PinJointParam, value: f32, )
Sets a pin joint parameter.
pub fn pin_joint_get_param(&self, joint: Rid, param: PinJointParam) -> f32
pub fn pin_joint_get_param(&self, joint: Rid, param: PinJointParam) -> f32
Returns the value of a pin joint parameter.
pub fn damped_spring_joint_set_param(
&mut self,
joint: Rid,
param: DampedSpringParam,
value: f32,
)
pub fn damped_spring_joint_set_param( &mut self, joint: Rid, param: DampedSpringParam, value: f32, )
Sets the value of the given damped spring joint parameter.
pub fn damped_spring_joint_get_param(
&self,
joint: Rid,
param: DampedSpringParam,
) -> f32
pub fn damped_spring_joint_get_param( &self, joint: Rid, param: DampedSpringParam, ) -> f32
Returns the value of the given damped spring joint parameter.
pub fn joint_get_type(&self, joint: Rid) -> JointType
pub fn joint_get_type(&self, joint: Rid) -> JointType
Returns the joint’s type.
pub fn free_rid(&mut self, rid: Rid)
pub fn free_rid(&mut self, 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.
pub fn set_active(&mut self, active: bool)
pub fn set_active(&mut self, 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.
pub fn get_process_info(&self, process_info: ProcessInfo) -> i32
pub fn get_process_info(&self, process_info: ProcessInfo) -> i32
Returns the value of a physics engine state specified by process_info.
Methods from Deref<Target = Object>§
pub fn get_script(&self) -> Option<Gd<Script>>
pub fn set_script(&mut self, script: impl AsArg<Option<Gd<Script>>>)
pub fn connect( &mut self, signal: impl AsArg<StringName>, callable: &Callable, ) -> Error
pub fn connect_flags( &mut self, signal: impl AsArg<StringName>, callable: &Callable, flags: ConnectFlags, ) -> Error
pub fn is_class(&self, class: impl AsArg<GString>) -> bool
pub fn is_class(&self, class: impl AsArg<GString>) -> bool
Returns true if the object inherits from the given class. See also get_class.
var sprite2d = Sprite2D.new()
sprite2d.is_class("Sprite2D") # Returns true
sprite2d.is_class("Node") # Returns true
sprite2d.is_class("Node3D") # Returns falseNote: This method ignores class_name declarations in the object’s script.
pub fn set(&mut self, property: impl AsArg<StringName>, value: &Variant)
pub fn set(&mut self, property: impl AsArg<StringName>, value: &Variant)
Assigns value to the given property. If the property does not exist or the given value’s type doesn’t match, nothing happens.
var node = Node2D.new()
node.set("global_scale", Vector2(8, 2.5))
print(node.global_scale) # Prints (8.0, 2.5)Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn get(&self, property: impl AsArg<StringName>) -> Variant
pub fn get(&self, property: impl AsArg<StringName>) -> Variant
Returns the Variant value of the given property. If the property does not exist, this method returns null.
var node = Node2D.new()
node.rotation = 1.5
var a = node.get("rotation") # a is 1.5Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn set_indexed(
&mut self,
property_path: impl AsArg<NodePath>,
value: &Variant,
)
pub fn set_indexed( &mut self, property_path: impl AsArg<NodePath>, value: &Variant, )
Assigns a new value to the property identified by the property_path. The path should be a NodePath relative to this object, and can use the colon character (:) to access nested properties.
var node = Node2D.new()
node.set_indexed("position", Vector2(42, 0))
node.set_indexed("position:y", -10)
print(node.position) # Prints (42.0, -10.0)Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn get_indexed(&self, property_path: impl AsArg<NodePath>) -> Variant
pub fn get_indexed(&self, property_path: impl AsArg<NodePath>) -> Variant
Gets the object’s property indexed by the given property_path. The path should be a NodePath relative to the current object and can use the colon character (:) to access nested properties.
Examples: "position:x" or "material:next_pass:blend_mode".
var node = Node2D.new()
node.position = Vector2(5, -10)
var a = node.get_indexed("position") # a is Vector2(5, -10)
var b = node.get_indexed("position:y") # b is -10Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
Note: This method does not support actual paths to nodes in the SceneTree, only sub-property paths. In the context of nodes, use get_node_and_resource instead.
pub fn get_property_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_property_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns the object’s property list as an Array of dictionaries. Each Dictionary contains the following entries:
-
nameis the property’s name, as aString; -
class_nameis an emptyStringName, unless the property isVariantType::OBJECTand it inherits from a class; -
typeis the property’s type, as anint(see [enum Variant.Type]); -
hintis how the property is meant to be edited (see [enum PropertyHint]); -
hint_stringdepends on the hint (see [enum PropertyHint]); -
usageis a combination of [enum PropertyUsageFlags].
Note: In GDScript, all class members are treated as properties. In C# and GDExtension, it may be necessary to explicitly mark class members as Godot properties using decorators or attributes.
pub fn get_method_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_method_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns this object’s methods and their signatures as an Array of dictionaries. Each Dictionary contains the following entries:
-
nameis the name of the method, as aString; -
argsis anArrayof dictionaries representing the arguments; -
default_argsis the default arguments as anArrayof variants; -
flagsis a combination of [enum MethodFlags]; -
idis the method’s internal identifierint; -
returnis the returned value, as aDictionary;
Note: The dictionaries of args and return are formatted identically to the results of get_property_list, although not all entries are used.
pub fn property_can_revert(&self, property: impl AsArg<StringName>) -> bool
pub fn property_can_revert(&self, property: impl AsArg<StringName>) -> bool
Returns true if the given property has a custom default value. Use property_get_revert to get the property’s default value.
Note: This method is used by the Inspector dock to display a revert icon. The object must implement [method _property_can_revert] to customize the default value. If [method _property_can_revert] is not implemented, this method returns false.
pub fn property_get_revert(&self, property: impl AsArg<StringName>) -> Variant
pub fn property_get_revert(&self, property: impl AsArg<StringName>) -> Variant
Returns the custom default value of the given property. Use property_can_revert to check if the property has a custom default value.
Note: This method is used by the Inspector dock to display a revert icon. The object must implement [method _property_get_revert] to customize the default value. If [method _property_get_revert] is not implemented, this method returns null.
pub fn set_meta(&mut self, name: impl AsArg<StringName>, value: &Variant)
pub fn set_meta(&mut self, name: impl AsArg<StringName>, value: &Variant)
Adds or changes the entry name inside the object’s metadata. The metadata value can be any Variant, although some types cannot be serialized correctly.
If value is null, the entry is removed. This is the equivalent of using remove_meta. See also has_meta and get_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn remove_meta(&mut self, name: impl AsArg<StringName>)
pub fn remove_meta(&mut self, name: impl AsArg<StringName>)
Removes the given entry name from the object’s metadata. See also has_meta, get_meta and set_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta(&self, name: impl AsArg<StringName>) -> Variant
pub fn get_meta(&self, name: impl AsArg<StringName>) -> Variant
To set the default parameters, use get_meta_ex and its builder methods. See the book for detailed usage instructions.
Returns the object’s metadata value for the given entry name. If the entry does not exist, returns default. If default is null, an error is also generated.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta_ex<'ex>(
&'ex self,
name: impl AsArg<StringName> + 'ex,
) -> ExGetMeta<'ex>
pub fn get_meta_ex<'ex>( &'ex self, name: impl AsArg<StringName> + 'ex, ) -> ExGetMeta<'ex>
Returns the object’s metadata value for the given entry name. If the entry does not exist, returns default. If default is null, an error is also generated.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn has_meta(&self, name: impl AsArg<StringName>) -> bool
pub fn has_meta(&self, name: impl AsArg<StringName>) -> bool
Returns true if a metadata entry is found with the given name. See also get_meta, set_meta and remove_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta_list(&self) -> Array<StringName>
pub fn get_meta_list(&self) -> Array<StringName>
Returns the object’s metadata entry names as an Array of StringNames.
pub fn add_user_signal(&mut self, signal: impl AsArg<GString>)
pub fn add_user_signal(&mut self, signal: impl AsArg<GString>)
To set the default parameters, use add_user_signal_ex and its builder methods. See the book for detailed usage instructions.
Adds a user-defined signal named signal. Optional arguments for the signal can be added as an Array of dictionaries, each defining a name String and a type int (see [enum Variant.Type]). See also has_user_signal and remove_user_signal.
add_user_signal("hurt", [
{ "name": "damage", "type": TYPE_INT },
{ "name": "source", "type": TYPE_OBJECT }
])pub fn add_user_signal_ex<'ex>(
&'ex mut self,
signal: impl AsArg<GString> + 'ex,
) -> ExAddUserSignal<'ex>
pub fn add_user_signal_ex<'ex>( &'ex mut self, signal: impl AsArg<GString> + 'ex, ) -> ExAddUserSignal<'ex>
Adds a user-defined signal named signal. Optional arguments for the signal can be added as an Array of dictionaries, each defining a name String and a type int (see [enum Variant.Type]). See also has_user_signal and remove_user_signal.
add_user_signal("hurt", [
{ "name": "damage", "type": TYPE_INT },
{ "name": "source", "type": TYPE_OBJECT }
])pub fn has_user_signal(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_user_signal(&self, signal: impl AsArg<StringName>) -> bool
Returns true if the given user-defined signal name exists. Only signals added with add_user_signal are included. See also remove_user_signal.
pub fn remove_user_signal(&mut self, signal: impl AsArg<StringName>)
pub fn remove_user_signal(&mut self, signal: impl AsArg<StringName>)
Removes the given user signal signal from the object. See also add_user_signal and has_user_signal.
pub fn emit_signal(
&mut self,
signal: impl AsArg<StringName>,
varargs: &[Variant],
) -> Error
pub fn emit_signal( &mut self, signal: impl AsArg<StringName>, varargs: &[Variant], ) -> Error
Emits the given signal by name. The signal must exist, so it should be a built-in signal of this class or one of its inherited classes, or a user-defined signal (see add_user_signal). This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
Returns Error::ERR_UNAVAILABLE if signal does not exist or the parameters are invalid.
emit_signal("hit", "sword", 100)
emit_signal("game_over")Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_emit_signal(
&mut self,
signal: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Error, CallError>
pub fn try_emit_signal( &mut self, signal: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Error, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn call(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Variant
pub fn call( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Variant
Calls the method on the object and returns the result. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
var node = Node3D.new()
node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_call(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Variant, CallError>
pub fn try_call( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Variant, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn call_deferred(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Variant
pub fn call_deferred( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Variant
Calls the method on the object during idle time. Always returns null, not the method’s result.
Idle time happens mainly at the end of process and physics frames. In it, deferred calls will be run until there are none left, which means you can defer calls from other deferred calls and they’ll still be run in the current idle time cycle. This means you should not call a method deferred from itself (or from a method called by it), as this causes infinite recursion the same way as if you had called the method directly.
This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
var node = Node3D.new()
node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)For methods that are deferred from the same thread, the order of execution at idle time is identical to the order in which call_deferred was called.
See also call_deferred.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
Note: If you’re looking to delay the function call by a frame, refer to the SceneTree.process_frame and SceneTree.physics_frame signals.
var node = Node3D.new()
# Make a Callable and bind the arguments to the node's rotate() call.
var callable = node.rotate.bind(Vector3(1.0, 0.0, 0.0), 1.571)
# Connect the callable to the process_frame signal, so it gets called in the next process frame.
# CONNECT_ONE_SHOT makes sure it only gets called once instead of every frame.
get_tree().process_frame.connect(callable, CONNECT_ONE_SHOT)§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_call_deferred(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Variant, CallError>
pub fn try_call_deferred( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Variant, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn set_deferred(
&mut self,
property: impl AsArg<StringName>,
value: &Variant,
)
pub fn set_deferred( &mut self, property: impl AsArg<StringName>, value: &Variant, )
Assigns value to the given property, at the end of the current frame. This is equivalent to calling set through call_deferred.
var node = Node2D.new()
add_child(node)
node.rotation = 1.5
node.set_deferred("rotation", 3.0)
print(node.rotation) # Prints 1.5
await get_tree().process_frame
print(node.rotation) # Prints 3.0Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn callv(
&mut self,
method: impl AsArg<StringName>,
arg_array: &AnyArray,
) -> Variant
pub fn callv( &mut self, method: impl AsArg<StringName>, arg_array: &AnyArray, ) -> Variant
Calls the method on the object and returns the result. Unlike call, this method expects all parameters to be contained inside arg_array.
var node = Node3D.new()
node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn has_method(&self, method: impl AsArg<StringName>) -> bool
pub fn has_method(&self, method: impl AsArg<StringName>) -> bool
Returns true if the given method name exists in the object.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn get_method_argument_count(&self, method: impl AsArg<StringName>) -> i32
pub fn get_method_argument_count(&self, method: impl AsArg<StringName>) -> i32
Returns the number of arguments of the given method by name.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn has_signal(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_signal(&self, signal: impl AsArg<StringName>) -> bool
Returns true if the given signal name exists in the object.
Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn get_signal_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_signal_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns the list of existing signals as an Array of dictionaries.
Note: Due to the implementation, each Dictionary is formatted very similarly to the returned values of get_method_list.
pub fn get_signal_connection_list(
&self,
signal: impl AsArg<StringName>,
) -> Array<Dictionary<Variant, Variant>>
pub fn get_signal_connection_list( &self, signal: impl AsArg<StringName>, ) -> Array<Dictionary<Variant, Variant>>
Returns an Array of connections for the given signal name. Each connection is represented as a Dictionary that contains three entries:
pub fn get_incoming_connections(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_incoming_connections(&self) -> Array<Dictionary<Variant, Variant>>
Returns an Array of signal connections received by this object. Each connection is represented as a Dictionary that contains three entries:
pub fn disconnect(
&mut self,
signal: impl AsArg<StringName>,
callable: &Callable,
)
pub fn disconnect( &mut self, signal: impl AsArg<StringName>, callable: &Callable, )
Disconnects a signal by name from a given callable. If the connection does not exist, generates an error. Use is_connected to make sure that the connection exists.
pub fn is_connected(
&self,
signal: impl AsArg<StringName>,
callable: &Callable,
) -> bool
pub fn is_connected( &self, signal: impl AsArg<StringName>, callable: &Callable, ) -> bool
Returns true if a connection exists between the given signal name and callable.
Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn has_connections(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_connections(&self, signal: impl AsArg<StringName>) -> bool
Returns true if any connection exists on the given signal name.
Note: In C#, signal must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn set_block_signals(&mut self, enable: bool)
pub fn set_block_signals(&mut self, enable: bool)
If set to true, the object becomes unable to emit signals. As such, emit_signal and signal connections will not work, until it is set to false.
pub fn is_blocking_signals(&self) -> bool
pub fn is_blocking_signals(&self) -> bool
Returns true if the object is blocking its signals from being emitted. See set_block_signals.
pub fn notify_property_list_changed(&mut self)
pub fn notify_property_list_changed(&mut self)
Emits the property_list_changed signal. This is mainly used to refresh the editor, so that the Inspector and editor plugins are properly updated.
pub fn set_message_translation(&mut self, enable: bool)
pub fn set_message_translation(&mut self, enable: bool)
If set to true, allows the object to translate messages with tr and tr_n. Enabled by default. See also can_translate_messages.
pub fn can_translate_messages(&self) -> bool
pub fn can_translate_messages(&self) -> bool
Returns true if the object is allowed to translate messages with tr and tr_n. See also set_message_translation.
pub fn tr(&self, message: impl AsArg<StringName>) -> GString
pub fn tr(&self, message: impl AsArg<StringName>) -> GString
To set the default parameters, use tr_ex and its builder methods. See the book for detailed usage instructions.
Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
If can_translate_messages is false, or no translation is available, this method returns the message without changes. See set_message_translation.
For detailed examples, see Internationalizing games.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate.
pub fn tr_ex<'ex>(&'ex self, message: impl AsArg<StringName> + 'ex) -> ExTr<'ex>
pub fn tr_ex<'ex>(&'ex self, message: impl AsArg<StringName> + 'ex) -> ExTr<'ex>
Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
If can_translate_messages is false, or no translation is available, this method returns the message without changes. See set_message_translation.
For detailed examples, see Internationalizing games.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate.
pub fn tr_n(
&self,
message: impl AsArg<StringName>,
plural_message: impl AsArg<StringName>,
n: i32,
) -> GString
pub fn tr_n( &self, message: impl AsArg<StringName>, plural_message: impl AsArg<StringName>, n: i32, ) -> GString
To set the default parameters, use tr_n_ex and its builder methods. See the book for detailed usage instructions.
Translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.
If can_translate_messages is false, or no translation is available, this method returns message or plural_message, without changes. See set_message_translation.
The n is the number, or amount, of the message’s subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see Localization using gettext.
Note: Negative and float numbers may not properly apply to some countable subjects. It’s recommended to handle these cases with tr.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate_plural.
pub fn tr_n_ex<'ex>(
&'ex self,
message: impl AsArg<StringName> + 'ex,
plural_message: impl AsArg<StringName> + 'ex,
n: i32,
) -> ExTrN<'ex>
pub fn tr_n_ex<'ex>( &'ex self, message: impl AsArg<StringName> + 'ex, plural_message: impl AsArg<StringName> + 'ex, n: i32, ) -> ExTrN<'ex>
Translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.
If can_translate_messages is false, or no translation is available, this method returns message or plural_message, without changes. See set_message_translation.
The n is the number, or amount, of the message’s subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see Localization using gettext.
Note: Negative and float numbers may not properly apply to some countable subjects. It’s recommended to handle these cases with tr.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate_plural.
pub fn get_translation_domain(&self) -> StringName
pub fn get_translation_domain(&self) -> StringName
Returns the name of the translation domain used by tr and tr_n. See also TranslationServer.
pub fn set_translation_domain(&mut self, domain: impl AsArg<StringName>)
pub fn set_translation_domain(&mut self, domain: impl AsArg<StringName>)
Sets the name of the translation domain used by tr and tr_n. See also TranslationServer.
pub fn is_queued_for_deletion(&self) -> bool
pub fn is_queued_for_deletion(&self) -> bool
Returns true if the queue_free method was called for the object.
pub fn cancel_free(&mut self)
pub fn cancel_free(&mut self)
If this method is called during ObjectNotification::PREDELETE, this object will reject being freed and will remain allocated. This is mostly an internal function used for error handling to avoid the user from freeing objects when they are not intended to.
pub fn notify(&mut self, what: ObjectNotification)
pub fn notify(&mut self, what: ObjectNotification)
⚠️ Sends a Godot notification to all classes inherited by the object.
Triggers calls to on_notification(), and depending on the notification, also to Godot’s lifecycle callbacks such as ready().
Starts from the highest ancestor (the Object class) and goes down the hierarchy.
See also Godot docs for Object::notification().
§Panics
If you call this method on a user-defined object while holding a GdRef or GdMut guard on the instance, you will encounter
a panic. The reason is that the receiving virtual method on_notification() acquires a GdMut lock dynamically, which must
be exclusive.
pub fn notify_reversed(&mut self, what: ObjectNotification)
pub fn notify_reversed(&mut self, what: ObjectNotification)
⚠️ Like Self::notify(), but starts at the most-derived class and goes up the hierarchy.
See docs of that method, including the panics.
Trait Implementations§
§impl Bounds for PhysicsServer2D
impl Bounds for PhysicsServer2D
§impl Debug for PhysicsServer2D
impl Debug for PhysicsServer2D
§impl Deref for PhysicsServer2D
impl Deref for PhysicsServer2D
§impl DerefMut for PhysicsServer2D
impl DerefMut for PhysicsServer2D
§fn deref_mut(&mut self) -> &mut <PhysicsServer2D as Deref>::Target
fn deref_mut(&mut self) -> &mut <PhysicsServer2D as Deref>::Target
§impl GodotClass for PhysicsServer2D
impl GodotClass for PhysicsServer2D
§const INIT_LEVEL: InitLevel = crate::init::InitLevel::Servers
const INIT_LEVEL: InitLevel = crate::init::InitLevel::Servers
§fn class_id() -> ClassId
fn class_id() -> ClassId
§fn inherits<Base>() -> boolwhere
Base: GodotClass,
fn inherits<Base>() -> boolwhere
Base: GodotClass,
§impl Inherits<Object> for PhysicsServer2D
impl Inherits<Object> for PhysicsServer2D
§const IS_SAME_CLASS: bool = false
const IS_SAME_CLASS: bool = false
Self == Base. Read more§impl Inherits<PhysicsServer2D> for PhysicsServer2DExtension
impl Inherits<PhysicsServer2D> for PhysicsServer2DExtension
§const IS_SAME_CLASS: bool = false
const IS_SAME_CLASS: bool = false
Self == Base. Read more§impl Singleton for PhysicsServer2D
impl Singleton for PhysicsServer2D
§fn singleton() -> Gd<PhysicsServer2D>
fn singleton() -> Gd<PhysicsServer2D>
§impl WithSignals for PhysicsServer2D
impl WithSignals for PhysicsServer2D
§type SignalCollection<'c, C: WithSignals> = SignalsOfObject<'c, C>
type SignalCollection<'c, C: WithSignals> = SignalsOfObject<'c, C>
Auto Trait Implementations§
impl Freeze for PhysicsServer2D
impl RefUnwindSafe for PhysicsServer2D
impl !Send for PhysicsServer2D
impl !Sync for PhysicsServer2D
impl Unpin for PhysicsServer2D
impl UnsafeUnpin for PhysicsServer2D
impl UnwindSafe for PhysicsServer2D
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Inherits<T> for Twhere
T: GodotClass,
impl<T> Inherits<T> for Twhere
T: GodotClass,
§const IS_SAME_CLASS: bool = true
const IS_SAME_CLASS: bool = true
Self == Base. Read more