pub trait RigidBodyForces: RigidBodyForcesInternal {
Show 23 methods
// Provided methods
fn apply_force(&mut self, force: Vector) { ... }
fn apply_force_at_point(&mut self, force: Vector, world_point: Vector) { ... }
fn apply_local_force(&mut self, force: Vector) { ... }
fn apply_torque(&mut self, torque: Scalar) { ... }
fn apply_linear_impulse(&mut self, impulse: Vector) { ... }
fn apply_linear_impulse_at_point(
&mut self,
impulse: Vector,
world_point: Vector,
) { ... }
fn apply_local_linear_impulse(&mut self, impulse: Vector) { ... }
fn apply_angular_impulse(&mut self, impulse: Scalar) { ... }
fn apply_linear_acceleration(&mut self, acceleration: Vector) { ... }
fn apply_linear_acceleration_at_point(
&mut self,
acceleration: Vector,
world_point: Vector,
) { ... }
fn apply_local_linear_acceleration(&mut self, acceleration: Vector) { ... }
fn apply_angular_acceleration(&mut self, acceleration: Scalar) { ... }
fn accumulated_linear_acceleration(&self) -> Vector { ... }
fn accumulated_angular_acceleration(&self) -> Scalar { ... }
fn reset_accumulated_linear_acceleration(&mut self) { ... }
fn reset_accumulated_angular_acceleration(&mut self) { ... }
fn position(&self) -> &Position { ... }
fn rotation(&self) -> &Rotation { ... }
fn linear_velocity(&self) -> Vector { ... }
fn linear_velocity_mut(&mut self) -> &mut Vector { ... }
fn angular_velocity(&self) -> Scalar { ... }
fn angular_velocity_mut(&mut self) -> &mut Scalar { ... }
fn velocity_at_point(&self, world_point: Vector) -> Vector { ... }
}
Expand description
A trait for applying forces, impulses, and accelerations to a dynamic rigid body.
This is implemented as a shared interface for the ForcesItem
and NonWakingForcesItem
returned by Forces
.
See the documentation of Forces
for more information on how to apply forces in Avian.
Provided Methods§
Sourcefn apply_force(&mut self, force: Vector)
fn apply_force(&mut self, force: Vector)
Applies a force at the center of mass in world space. The unit is typically N or kg⋅m/s².
The force is applied continuously over the physics step and cleared afterwards.
By default, a non-zero force will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn apply_force_at_point(&mut self, force: Vector, world_point: Vector)
fn apply_force_at_point(&mut self, force: Vector, world_point: Vector)
Applies a force at the given point in world space. The unit is typically N or kg⋅m/s².
If the point is not at the center of mass, the force will also generate a torque.
The force is applied continuously over the physics step and cleared afterwards.
By default, a non-zero force will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
§Note
If the Transform
of the body is modified before applying the force,
the torque will be computed using an outdated global center of mass.
This may cause problems when applying a force right after teleporting
an entity, as the torque could grow very large if the distance between the point
and old center of mass is large.
In case this is causing problems, consider using the PhysicsTransformHelper
to update the global physics transform after modifying Transform
.
Sourcefn apply_local_force(&mut self, force: Vector)
fn apply_local_force(&mut self, force: Vector)
Applies a force at the center of mass in local space. The unit is typically N or kg⋅m/s².
The force is applied continuously over the physics step and cleared afterwards.
By default, a non-zero force will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn apply_torque(&mut self, torque: Scalar)
fn apply_torque(&mut self, torque: Scalar)
Applies a torque in world space. The unit is typically N⋅m or kg⋅m²/s².
The torque is applied continuously over the physics step and cleared afterwards.
By default, a non-zero torque will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn apply_linear_impulse(&mut self, impulse: Vector)
fn apply_linear_impulse(&mut self, impulse: Vector)
Applies a linear impulse at the center of mass in world space. The unit is typically N⋅s or kg⋅m/s.
The impulse modifies the LinearVelocity
of the body immediately.
By default, a non-zero impulse will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn apply_linear_impulse_at_point(
&mut self,
impulse: Vector,
world_point: Vector,
)
fn apply_linear_impulse_at_point( &mut self, impulse: Vector, world_point: Vector, )
Applies a linear impulse at the given point in world space. The unit is typically N⋅s or kg⋅m/s.
If the point is not at the center of mass, the impulse will also generate an angular impulse.
The impulse modifies the LinearVelocity
and AngularVelocity
of the body immediately.
By default, a non-zero impulse will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
§Note
If the Transform
of the body is modified before applying the impulse,
the torque will be computed using an outdated global center of mass.
This may cause problems when applying a impulse right after teleporting
an entity, as the torque could grow very large if the distance between the point
and old center of mass is large.
In case this is causing problems, consider using the PhysicsTransformHelper
to update the global physics transform after modifying Transform
.
Sourcefn apply_local_linear_impulse(&mut self, impulse: Vector)
fn apply_local_linear_impulse(&mut self, impulse: Vector)
Applies a linear impulse in local space. The unit is typically N⋅s or kg⋅m/s.
The impulse modifies the LinearVelocity
of the body immediately.
By default, a non-zero impulse will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn apply_angular_impulse(&mut self, impulse: Scalar)
fn apply_angular_impulse(&mut self, impulse: Scalar)
Applies an angular impulse in world space. The unit is typically N⋅m⋅s or kg⋅m²/s.
The impulse modifies the AngularVelocity
of the body immediately.
By default, a non-zero impulse will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn apply_linear_acceleration(&mut self, acceleration: Vector)
fn apply_linear_acceleration(&mut self, acceleration: Vector)
Applies a linear acceleration, ignoring mass. The unit is typically m/s².
The acceleration is applied continuously over the physics step and cleared afterwards.
By default, a non-zero acceleration will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn apply_linear_acceleration_at_point(
&mut self,
acceleration: Vector,
world_point: Vector,
)
fn apply_linear_acceleration_at_point( &mut self, acceleration: Vector, world_point: Vector, )
Applies a linear acceleration at the given point in world space. The unit is typically m/s².
If the point is not at the center of mass, the acceleration will also generate an angular acceleration.
The acceleration is applied continuously over the physics step and cleared afterwards.
By default, a non-zero acceleration will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
§Note
If the Transform
of the body is modified before applying the acceleration,
the angular acceleration will be computed using an outdated global center of mass.
This may cause problems when applying a acceleration right after teleporting
an entity, as the angular acceleration could grow very large if the distance between the point
and old center of mass is large.
In case this is causing problems, consider using the PhysicsTransformHelper
to update the global physics transform after modifying Transform
.
Sourcefn apply_local_linear_acceleration(&mut self, acceleration: Vector)
fn apply_local_linear_acceleration(&mut self, acceleration: Vector)
Applies a linear acceleration in local space, ignoring mass. The unit is typically m/s².
The acceleration is applied continuously over the physics step and cleared afterwards.
By default, a non-zero acceleration will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn apply_angular_acceleration(&mut self, acceleration: Scalar)
fn apply_angular_acceleration(&mut self, acceleration: Scalar)
Applies an angular acceleration, ignoring angular inertia. The unit is rad/s².
The acceleration is applied continuously over the physics step and cleared afterwards.
By default, a non-zero acceleration will wake up the body if it is sleeping. This can be prevented
by first calling ForcesItem::non_waking
to get a NonWakingForcesItem
.
Sourcefn accumulated_linear_acceleration(&self) -> Vector
fn accumulated_linear_acceleration(&self) -> Vector
Returns the linear acceleration that the body has accumulated before the physics step in world space, including acceleration caused by forces.
This does not include gravity, contact forces, or joint forces.
Only forces and accelerations applied through Forces
are included.
Sourcefn accumulated_angular_acceleration(&self) -> Scalar
fn accumulated_angular_acceleration(&self) -> Scalar
Returns the angular acceleration that the body has accumulated before the physics step in world space, including acceleration caused by torques.
This does not include gravity, contact forces, or joint forces.
Only torques and accelerations applied through Forces
are included.
Sourcefn reset_accumulated_linear_acceleration(&mut self)
fn reset_accumulated_linear_acceleration(&mut self)
Resets the accumulated linear acceleration to zero.
Sourcefn reset_accumulated_angular_acceleration(&mut self)
fn reset_accumulated_angular_acceleration(&mut self)
Resets the accumulated angular acceleration to zero.
Sourcefn linear_velocity(&self) -> Vector
fn linear_velocity(&self) -> Vector
Returns the LinearVelocity
of the body in world space.
Sourcefn linear_velocity_mut(&mut self) -> &mut Vector
fn linear_velocity_mut(&mut self) -> &mut Vector
Returns a mutable reference to the LinearVelocity
of the body in world space.
Sourcefn angular_velocity(&self) -> Scalar
fn angular_velocity(&self) -> Scalar
Returns the AngularVelocity
of the body in world space.
Sourcefn angular_velocity_mut(&mut self) -> &mut Scalar
fn angular_velocity_mut(&mut self) -> &mut Scalar
Returns a mutable reference to the AngularVelocity
of the body in world space.
Sourcefn velocity_at_point(&self, world_point: Vector) -> Vector
fn velocity_at_point(&self, world_point: Vector) -> Vector
Returns the velocity of a point in world space on the body.