pub enum ColliderShape {
Circle {
radius: f32,
},
Aabb {
half_extents: Vec2,
},
Obb {
half_extents: Vec2,
},
Capsule {
half_height: f32,
radius: f32,
},
Polygon {
vertices: Vec<Vec2>,
},
}Expand description
The geometric shape of a collider.
Each shape type has different performance characteristics and use cases:
- Circle: Fastest collision detection, best for balls, projectiles
- Box: Axis-aligned (AABB) or oriented (OBB), good for walls and platforms
- Capsule: Good for characters, combines efficiency with smooth edges
- Polygon: Most flexible but slowest, use sparingly for complex shapes
Variants§
Circle
Circle collider defined by radius.
Center is at the entity’s position. Fastest collision detection.
Aabb
Axis-Aligned Bounding Box (AABB).
Defined by half-extents (half-width, half-height) from the center. Fast collision detection, no rotation support.
Obb
Oriented Bounding Box (OBB).
Similar to AABB but can be rotated. Slightly slower than AABB.
Capsule
Capsule collider (rounded rectangle).
Defined by half-height and radius. Good for character controllers. The capsule extends vertically from the center.
Fields
Polygon
Convex polygon collider.
Vertices must be in counter-clockwise order and form a convex hull. Slowest collision detection, use sparingly.
Implementations§
Source§impl ColliderShape
impl ColliderShape
Sourcepub fn compute_aabb(&self) -> Rect
pub fn compute_aabb(&self) -> Rect
Computes the axis-aligned bounding box (AABB) for this shape.
Returns a rectangle in local space that fully contains the shape. For rotated shapes (OBB, Polygon), this is a conservative bound.
Sourcepub fn is_capsule(&self) -> bool
pub fn is_capsule(&self) -> bool
Returns true if this shape is a capsule.
Sourcepub fn is_polygon(&self) -> bool
pub fn is_polygon(&self) -> bool
Returns true if this shape is a polygon.
Trait Implementations§
Source§impl Clone for ColliderShape
impl Clone for ColliderShape
Source§fn clone(&self) -> ColliderShape
fn clone(&self) -> ColliderShape
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ColliderShape
impl Debug for ColliderShape
Source§impl Default for ColliderShape
impl Default for ColliderShape
Source§fn default() -> ColliderShape
fn default() -> ColliderShape
Returns a unit circle (radius 1.0) as the default shape.
Source§impl<'de> Deserialize<'de> for ColliderShape
impl<'de> Deserialize<'de> for ColliderShape
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ColliderShape, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ColliderShape, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ColliderShape
impl PartialEq for ColliderShape
Source§impl Serialize for ColliderShape
impl Serialize for ColliderShape
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ColliderShape
Auto Trait Implementations§
impl Freeze for ColliderShape
impl RefUnwindSafe for ColliderShape
impl Send for ColliderShape
impl Sync for ColliderShape
impl Unpin for ColliderShape
impl UnsafeUnpin for ColliderShape
impl UnwindSafe for ColliderShape
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().