pub struct Collider { /* private fields */ }Expand description
Collider component for physics collision detection.
Defines the collision shape, material properties (friction, restitution), and filtering (layers, masks) for an entity.
§Examples
use goud_engine::ecs::components::Collider;
use goud_engine::core::math::Vec2;
// Circle collider
let ball = Collider::circle(0.5);
// Box collider
let wall = Collider::aabb(Vec2::new(5.0, 1.0));
// Capsule collider
let player = Collider::capsule(0.3, 1.0);
// Sensor (trigger)
let trigger = Collider::circle(2.0).with_is_sensor(true);Implementations§
Source§impl Collider
impl Collider
Sourcepub fn circle(radius: f32) -> Collider
pub fn circle(radius: f32) -> Collider
Creates a new circle collider with the given radius.
§Examples
use goud_engine::ecs::components::Collider;
let ball = Collider::circle(0.5);Sourcepub fn aabb(half_extents: Vec2) -> Collider
pub fn aabb(half_extents: Vec2) -> Collider
Creates a new axis-aligned box collider with the given half-extents.
§Examples
use goud_engine::ecs::components::Collider;
use goud_engine::core::math::Vec2;
// 10x2 box (half-extents are half the size)
let wall = Collider::aabb(Vec2::new(5.0, 1.0));Sourcepub fn obb(half_extents: Vec2) -> Collider
pub fn obb(half_extents: Vec2) -> Collider
Creates a new oriented box collider with the given half-extents.
Similar to aabb() but supports rotation via the entity’s Transform2D.
Sourcepub fn capsule(half_height: f32, radius: f32) -> Collider
pub fn capsule(half_height: f32, radius: f32) -> Collider
Creates a new capsule collider with the given half-height and radius.
Good for character controllers with smooth movement.
§Examples
use goud_engine::ecs::components::Collider;
// Capsule with 0.6 radius and 2.0 total height
let player = Collider::capsule(0.3, 1.0);Sourcepub fn polygon(vertices: Vec<Vec2>) -> Collider
pub fn polygon(vertices: Vec<Vec2>) -> Collider
Creates a new convex polygon collider with the given vertices.
Vertices must be in counter-clockwise order and form a convex hull.
§Panics
Panics if fewer than 3 vertices are provided.
Sourcepub fn with_restitution(self, restitution: f32) -> Collider
pub fn with_restitution(self, restitution: f32) -> Collider
Sets the restitution (bounciness) coefficient.
0.0 = no bounce, 1.0 = perfect bounce.
Sourcepub fn with_friction(self, friction: f32) -> Collider
pub fn with_friction(self, friction: f32) -> Collider
Sets the friction coefficient.
0.0 = frictionless, 1.0 = high friction.
Sourcepub fn with_density(self, density: f32) -> Collider
pub fn with_density(self, density: f32) -> Collider
Sets the density for automatic mass calculation.
Mass will be calculated as: area × density
Sourcepub fn with_layer(self, layer: u32) -> Collider
pub fn with_layer(self, layer: u32) -> Collider
Sets the collision layer bitmask.
Sourcepub fn with_is_sensor(self, is_sensor: bool) -> Collider
pub fn with_is_sensor(self, is_sensor: bool) -> Collider
Sets whether this collider is a sensor (trigger).
Sourcepub fn with_enabled(self, enabled: bool) -> Collider
pub fn with_enabled(self, enabled: bool) -> Collider
Sets whether this collider is enabled.
Sourcepub fn shape(&self) -> &ColliderShape
pub fn shape(&self) -> &ColliderShape
Returns a reference to the collision shape.
Sourcepub fn restitution(&self) -> f32
pub fn restitution(&self) -> f32
Returns the restitution coefficient.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true if this collider is enabled.
Sourcepub fn compute_aabb(&self) -> Rect
pub fn compute_aabb(&self) -> Rect
Computes the axis-aligned bounding box (AABB) for this collider.
Sourcepub fn can_collide_with(&self, other: &Collider) -> bool
pub fn can_collide_with(&self, other: &Collider) -> bool
Checks if this collider can collide with another based on layer filtering.
Returns true if: (self.layer & other.mask) != 0 && (other.layer & self.mask) != 0
Sourcepub fn set_restitution(&mut self, restitution: f32)
pub fn set_restitution(&mut self, restitution: f32)
Sets the restitution coefficient.
Sourcepub fn set_friction(&mut self, friction: f32)
pub fn set_friction(&mut self, friction: f32)
Sets the friction coefficient.
Sourcepub fn set_density(&mut self, density: Option<f32>)
pub fn set_density(&mut self, density: Option<f32>)
Sets the density for automatic mass calculation.
Sourcepub fn set_is_sensor(&mut self, is_sensor: bool)
pub fn set_is_sensor(&mut self, is_sensor: bool)
Sets whether this collider is a sensor.
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Sets whether this collider is enabled.
Sourcepub fn set_shape(&mut self, shape: ColliderShape)
pub fn set_shape(&mut self, shape: ColliderShape)
Replaces the collision shape.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Collider
impl<'de> Deserialize<'de> for Collider
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Collider, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Collider, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Collider
impl Serialize for Collider
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 Component for Collider
impl StructuralPartialEq for Collider
Auto Trait Implementations§
impl Freeze for Collider
impl RefUnwindSafe for Collider
impl Send for Collider
impl Sync for Collider
impl Unpin for Collider
impl UnsafeUnpin for Collider
impl UnwindSafe for Collider
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().