pub struct RigidBody2D {
pub id: u64,
pub position: Vector2D,
pub velocity: Vector2D,
pub force_accumulator: Vector2D,
pub angular_velocity: f64,
pub mass: f64,
pub inverse_mass: f64,
pub friction: f64,
pub body_type: BodyType,
/* private fields */
}Expand description
A 2D rigid body participating in the physics simulation.
Fields§
§id: u64The unique identifier of this body, typically matching a game object ID.
position: Vector2DThe world-space position of the body’s center.
velocity: Vector2DThe linear velocity in pixels per second.
force_accumulator: Vector2DThe accumulated force to be applied during the next physics step.
angular_velocity: f64The angular velocity in radians per second.
mass: f64The mass of the body in kilograms. Static bodies have a mass of 0.
inverse_mass: f64The precomputed inverse mass (1/mass). Static bodies have 0 inverse mass.
friction: f64The friction coefficient for surface contact.
body_type: BodyTypeHow this body participates in the simulation.
Implementations§
Source§impl RigidBody2D
Implements body creation and force management for RigidBody2D.
impl RigidBody2D
Implements body creation and force management for RigidBody2D.
Sourcepub fn new_dynamic(id: u64, position: Vector2D) -> RigidBody2D
pub fn new_dynamic(id: u64, position: Vector2D) -> RigidBody2D
Sourcepub fn new_static(id: u64, position: Vector2D) -> RigidBody2D
pub fn new_static(id: u64, position: Vector2D) -> RigidBody2D
Sourcepub fn apply_force(&mut self, force: Vector2D)
pub fn apply_force(&mut self, force: Vector2D)
Sourcepub fn apply_impulse(&mut self, impulse: Vector2D)
pub fn apply_impulse(&mut self, impulse: Vector2D)
Applies an instantaneous impulse, directly changing velocity.
§Arguments
Vector2D- The impulse vector.
Sourcepub fn update_mass(&mut self, mass: f64)
pub fn update_mass(&mut self, mass: f64)
Sets the mass of the body, updating the inverse mass. A mass of 0 makes the body static (infinite mass).
§Arguments
f64- The new mass.
Sourcepub fn is_dynamic(&self) -> bool
pub fn is_dynamic(&self) -> bool
Returns true if this body is affected by forces and collisions.
§Returns
bool- True if the body is dynamic.
Sourcepub fn update_collider(&mut self, collider: BodyCollider)
pub fn update_collider(&mut self, collider: BodyCollider)
Sourcepub fn bounding_box(&self) -> Option<Rect>
pub fn bounding_box(&self) -> Option<Rect>
Returns the world-space bounding box of the attached collider, if any.
§Returns
Option<Rect>- The bounding box, orNoneif no collider is attached.