Skip to main content

Collider

Struct Collider 

Source
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

Source

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);
Source

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));
Source

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.

Source

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);
Source

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.

Source

pub fn with_restitution(self, restitution: f32) -> Collider

Sets the restitution (bounciness) coefficient.

0.0 = no bounce, 1.0 = perfect bounce.

Source

pub fn with_friction(self, friction: f32) -> Collider

Sets the friction coefficient.

0.0 = frictionless, 1.0 = high friction.

Source

pub fn with_density(self, density: f32) -> Collider

Sets the density for automatic mass calculation.

Mass will be calculated as: area × density

Source

pub fn with_layer(self, layer: u32) -> Collider

Sets the collision layer bitmask.

Source

pub fn with_mask(self, mask: u32) -> Collider

Sets the collision mask bitmask.

Source

pub fn with_is_sensor(self, is_sensor: bool) -> Collider

Sets whether this collider is a sensor (trigger).

Source

pub fn with_enabled(self, enabled: bool) -> Collider

Sets whether this collider is enabled.

Source

pub fn shape(&self) -> &ColliderShape

Returns a reference to the collision shape.

Source

pub fn restitution(&self) -> f32

Returns the restitution coefficient.

Source

pub fn friction(&self) -> f32

Returns the friction coefficient.

Source

pub fn density(&self) -> Option<f32>

Returns the density, if set.

Source

pub fn layer(&self) -> u32

Returns the collision layer.

Source

pub fn mask(&self) -> u32

Returns the collision mask.

Source

pub fn is_sensor(&self) -> bool

Returns true if this collider is a sensor (trigger).

Source

pub fn is_enabled(&self) -> bool

Returns true if this collider is enabled.

Source

pub fn compute_aabb(&self) -> Rect

Computes the axis-aligned bounding box (AABB) for this collider.

Source

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

Source

pub fn set_restitution(&mut self, restitution: f32)

Sets the restitution coefficient.

Source

pub fn set_friction(&mut self, friction: f32)

Sets the friction coefficient.

Source

pub fn set_density(&mut self, density: Option<f32>)

Sets the density for automatic mass calculation.

Source

pub fn set_layer(&mut self, layer: u32)

Sets the collision layer.

Source

pub fn set_mask(&mut self, mask: u32)

Sets the collision mask.

Source

pub fn set_is_sensor(&mut self, is_sensor: bool)

Sets whether this collider is a sensor.

Source

pub fn set_enabled(&mut self, enabled: bool)

Sets whether this collider is enabled.

Source

pub fn set_shape(&mut self, shape: ColliderShape)

Replaces the collision shape.

Trait Implementations§

Source§

impl Clone for Collider

Source§

fn clone(&self) -> Collider

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Collider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Collider

Source§

fn default() -> Collider

Returns a default circle collider with radius 0.5.

Source§

impl Display for Collider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Collider

Source§

fn eq(&self, other: &Collider) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Component for Collider

Source§

impl StructuralPartialEq for Collider

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> QueryState for T
where T: Send + Sync + Clone + 'static,

Source§

impl<T> Resource for T
where T: Send + Sync + 'static,