Struct gdnative_bindings_lily::RigidBody2D [−][src]
pub struct RigidBody2D { /* fields omitted */ }
Expand description
core class RigidBody2D
inherits PhysicsBody2D
(unsafe).
Official documentation
See the documentation of this class in the Godot engine’s official documentation. The method descriptions are generated from it and typically contain code samples in GDScript, not Rust.
Memory management
Non reference counted objects such as the ones of this type are usually owned by the engine.
RigidBody2D
is a reference-only type. Persistent references can
only exist in the unsafe Ref<RigidBody2D>
form.
In the cases where Rust code owns an object of this type, for example if the object was just
created on the Rust side and not passed to the engine yet, ownership should be either given
to the engine or the object must be manually destroyed using Ref::free
, or Ref::queue_free
if it is a Node
.
Class hierarchy
RigidBody2D inherits methods from:
Safety
All types in the Godot API have “interior mutability” in Rust parlance.
To enforce that the official thread-safety guidelines are
followed, the typestate pattern is used in the Ref
and TRef
smart pointers,
and the Instance
API. The typestate Access
in these types tracks whether the
access is unique, shared, or exclusive to the current thread. For more information,
see the type-level documentation on Ref
.
Implementations
Constants
Creates a new instance of this object.
Because this type is not reference counted, the lifetime of the returned object is not automatically managed.
Immediately after creation, the object is owned by the caller, and can be
passed to the engine (in which case the engine will be responsible for
destroying the object) or destroyed manually using Ref::free
, or preferably
Ref::queue_free
if it is a Node
.
Adds a constant directional force without affecting rotation.
Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.
Adds a constant rotational force.
Applies a directional impulse without affecting rotation.
Applies a positioned impulse to the body. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts (use the “_force” functions otherwise). The position uses the rotation of the global coordinate system, but is centered at the object’s origin.
Applies a rotational impulse to the body.
Damps the body’s [member angular_velocity]. If -1
, the body will use the Default Angular Damp defined in Project > Project Settings > Physics > 2d.
The body’s rotational velocity.
The body’s total applied force.
The body’s total applied torque.
The body’s bounciness. Values range from 0
(no bounce) to 1
(full bounciness).
Deprecated, use [member PhysicsMaterial.bounce] instead via [member physics_material_override].
Returns a list of the bodies colliding with this one. Requires [member contact_monitor] to be set to true
and [member contacts_reported] to be set high enough to detect all the collisions.
Note: The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.
Continuous collision detection mode. Continuous collision detection tries to predict where a moving body will collide instead of moving it and correcting its movement after collision. Continuous collision detection is slower, but more precise and misses fewer collisions with small, fast-moving objects. Raycasting and shapecasting methods are available. See [enum CCDMode] for details.
The body’s friction. Values range from 0
(frictionless) to 1
(maximum friction).
Deprecated, use [member PhysicsMaterial.friction] instead via [member physics_material_override].
Multiplies the gravity applied to the body. The body’s gravity is calculated from the Default Gravity value in Project > Project Settings > Physics > 2d and/or any additional gravity vector applied by Area2Ds.
The body’s moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this function allows you to set a custom value. Set 0 inertia to return to automatically computing it.
Damps the body’s [member linear_velocity]. If -1
, the body will use the Default Linear Damp in Project > Project Settings > Physics > 2d.
The body’s linear velocity.
The maximum number of contacts that will be recorded. Requires [member contact_monitor] to be set to true
.
Note: The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end), and collisions between parallel faces will result in four contacts (one at each corner).
The physics material override for the body. If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one.
The body’s weight based on its mass and the Default Gravity value in Project > Project Settings > Physics > 2d.
If true
, the body can enter sleep mode when there is no movement. See [member sleeping].
Note: A RigidBody2D will never enter sleep mode automatically if its [member mode] is [constant MODE_CHARACTER]. It can still be put to sleep manually by setting its [member sleeping] property to true
.
If true
, the body will emit signals when it collides with another RigidBody2D. See also [member contacts_reported].
If true
, the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the [method apply_impulse] or [method add_force] methods.
If true
, internal force integration is disabled for this body. Aside from collision response, the body will only move as determined by the [method _integrate_forces] function.
Damps the body’s [member angular_velocity]. If -1
, the body will use the Default Angular Damp defined in Project > Project Settings > Physics > 2d.
The body’s rotational velocity.
The body’s total applied force.
The body’s total applied torque.
Sets the body’s velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
The body’s bounciness. Values range from 0
(no bounce) to 1
(full bounciness).
Deprecated, use [member PhysicsMaterial.bounce] instead via [member physics_material_override].
If true
, the body can enter sleep mode when there is no movement. See [member sleeping].
Note: A RigidBody2D will never enter sleep mode automatically if its [member mode] is [constant MODE_CHARACTER]. It can still be put to sleep manually by setting its [member sleeping] property to true
.
If true
, the body will emit signals when it collides with another RigidBody2D. See also [member contacts_reported].
Continuous collision detection mode. Continuous collision detection tries to predict where a moving body will collide instead of moving it and correcting its movement after collision. Continuous collision detection is slower, but more precise and misses fewer collisions with small, fast-moving objects. Raycasting and shapecasting methods are available. See [enum CCDMode] for details.
The body’s friction. Values range from 0
(frictionless) to 1
(maximum friction).
Deprecated, use [member PhysicsMaterial.friction] instead via [member physics_material_override].
Multiplies the gravity applied to the body. The body’s gravity is calculated from the Default Gravity value in Project > Project Settings > Physics > 2d and/or any additional gravity vector applied by Area2Ds.
The body’s moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this function allows you to set a custom value. Set 0 inertia to return to automatically computing it.
Damps the body’s [member linear_velocity]. If -1
, the body will use the Default Linear Damp in Project > Project Settings > Physics > 2d.
The body’s linear velocity.
The maximum number of contacts that will be recorded. Requires [member contact_monitor] to be set to true
.
Note: The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end), and collisions between parallel faces will result in four contacts (one at each corner).
pub fn set_physics_material_override(
&self,
physics_material_override: impl AsArg<PhysicsMaterial>
)
pub fn set_physics_material_override(
&self,
physics_material_override: impl AsArg<PhysicsMaterial>
)
The physics material override for the body. If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one.
If true
, the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the [method apply_impulse] or [method add_force] methods.
If true
, internal force integration is disabled for this body. Aside from collision response, the body will only move as determined by the [method _integrate_forces] function.
The body’s weight based on its mass and the Default Gravity value in Project > Project Settings > Physics > 2d.
pub fn test_motion(
&self,
motion: Vector2,
infinite_inertia: bool,
margin: f64,
result: impl AsArg<Physics2DTestMotionResult>
) -> bool
pub fn test_motion(
&self,
motion: Vector2,
infinite_inertia: bool,
margin: f64,
result: impl AsArg<Physics2DTestMotionResult>
) -> bool
Returns true
if a collision would result from moving in the given vector. margin
increases the size of the shapes involved in the collision detection, and result
is an object of type Physics2DTestMotionResult, which contains additional information about the collision (should there be one).
Default Arguments
infinite_inertia
-true
margin
-0.08
result
-null
Methods from Deref<Target = PhysicsBody2D>
Adds a body to the list of bodies that this body can’t collide with.
Returns an array of nodes that were added as collision exceptions for this body.
The physics layers this area is in. Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the [member collision_mask] property. A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
Returns an individual bit on the [member collision_layer].
The physics layers this area scans for collisions. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
Returns an individual bit on the [member collision_mask].
Removes a body from the list of bodies that this body can’t collide with.
The physics layers this area is in. Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the [member collision_mask] property. A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
Sets individual bits on the [member collision_layer] bitmask. Use this if you only need to change one layer’s value.
The physics layers this area scans for collisions. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information.
Sets individual bits on the [member collision_mask] bitmask. Use this if you only need to change one layer’s value.
Trait Implementations
type Target = PhysicsBody2D
type Target = PhysicsBody2D
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
type RefKind = ManuallyManaged
type RefKind = ManuallyManaged
Creates an explicitly null reference of Self
as a method argument. This makes type
inference easier for the compiler compared to Option
. Read more
Creates a new instance of Self
using a zero-argument constructor, as a Unique
reference. Read more
Performs a dynamic reference downcast to target type. Read more
Performs a static reference upcast to a supertype that is guaranteed to be valid. Read more
Creates a persistent reference to the same Godot object with shared thread access. Read more
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
unsafe fn assume_thread_local(&self) -> Ref<Self, ThreadLocal> where
Self: GodotObject<RefKind = RefCounted>,
Creates a persistent reference to the same Godot object with thread-local thread access. Read more
Creates a persistent reference to the same Godot object with unique access. Read more
Recovers a instance ID previously returned by Object::get_instance_id
if the object is
still alive. See also TRef::try_from_instance_id
. Read more
Auto Trait Implementations
impl RefUnwindSafe for RigidBody2D
impl !Send for RigidBody2D
impl !Sync for RigidBody2D
impl Unpin for RigidBody2D
impl UnwindSafe for RigidBody2D