pub struct Body2D {
pub position: Vec2,
pub half_size: Vec2,
pub velocity: Vec2,
pub grounded: bool,
}Expand description
Simple swept 2D character body. Positive Y is down.
Fields§
§position: Vec2Center position in world units.
half_size: Vec2Half dimensions of the collision box.
velocity: Vec2Velocity in world units per second.
grounded: boolWhether the last movement touched a solid while moving down.
Implementations§
Source§impl Body2D
impl Body2D
Sourcepub fn new(position: Vec2, size: Vec2) -> Self
pub fn new(position: Vec2, size: Vec2) -> Self
Creates a stationary body from its center and full dimensions.
Sourcepub fn move_and_slide(&mut self, dt: f32, solids: &[Aabb2])
pub fn move_and_slide(&mut self, dt: f32, solids: &[Aabb2])
Integrates velocity and slides along static boxes, resolving X then Y.
Clipped velocity components become zero. dt must be finite and nonnegative.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Body2D
impl RefUnwindSafe for Body2D
impl Send for Body2D
impl Sync for Body2D
impl Unpin for Body2D
impl UnsafeUnpin for Body2D
impl UnwindSafe for Body2D
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
Mutably borrows from an owned value. Read more