pub struct RectangleCollider2d { /* private fields */ }Expand description
An axis-aligned rectangular collision area centered on an entity’s
Transform2d.
size is the full width and height in caller-defined world units. This
component describes overlap geometry only: it does not automatically
inherit or track geometry from crate::visual::RectangleVisual, move
entities, or resolve collisions. Self::from_visual can explicitly copy
the initial full size once, but it ignores rounded corners, does not copy a
transform, and does not synchronize later changes. Keeping geometry
independent permits invisible hit areas and visuals whose shape differs
from gameplay. Spawning this component without a Transform2d
automatically inserts a default transform at the world origin. The
canonical translation of a transform supplied in the same bundle takes
precedence; normal spawn snapping may reset its previous interpolation
endpoint to that translation.
Implementations§
Source§impl RectangleCollider2d
impl RectangleCollider2d
Sourcepub fn new(size: Vec2) -> Result<Self, RectangleColliderError>
pub fn new(size: Vec2) -> Result<Self, RectangleColliderError>
Creates a collider with finite, strictly positive full width and height.
Sourcepub const fn from_visual(visual: &RectangleVisual) -> Self
pub const fn from_visual(visual: &RectangleVisual) -> Self
Copies the initial full size of a rectangle visual into a new collider.
Corner radius and presentation properties are not collision geometry
and are ignored. This is a one-time snapshot, not synchronization, and
it does not copy a transform. Later size changes on either value do not
affect the other. Use Self::new for deliberately different or
invisible hit areas.
Sourcepub const fn size(&self) -> Vec2
pub const fn size(&self) -> Vec2
Returns the full width and height in caller-defined world units.
Sourcepub fn set_size(&mut self, size: Vec2) -> Result<(), RectangleColliderError>
pub fn set_size(&mut self, size: Vec2) -> Result<(), RectangleColliderError>
Replaces the full width and height after validation.
A rejected value leaves the complete previous size unchanged.
Sourcepub fn overlaps(
&self,
transform: &Transform2d,
other: &Self,
other_transform: &Transform2d,
) -> bool
pub fn overlaps( &self, transform: &Transform2d, other: &Self, other_transform: &Transform2d, ) -> bool
Reports whether two colliders overlap at their canonical transforms.
Rectangles are axis-aligned and edge or corner contact counts as
overlap. Calculation widens positions and sizes to f64 before
arithmetic, preventing overflow for finite f32 values. Render
interpolation, visual corner radius, rotation, and scale are not
involved.
Sourcepub fn overlaps_circle(
&self,
transform: &Transform2d,
circle: &CircleCollider2d,
circle_transform: &Transform2d,
) -> bool
pub fn overlaps_circle( &self, transform: &Transform2d, circle: &CircleCollider2d, circle_transform: &Transform2d, ) -> bool
Reports whether this axis-aligned rectangle overlaps a circle.
This is the symmetric orientation of
CircleCollider2d::overlaps_rectangle and delegates to the same
widened closed-contact predicate.
Trait Implementations§
Source§impl Clone for RectangleCollider2d
impl Clone for RectangleCollider2d
Source§impl Component for RectangleCollider2d
Required Components: Transform2d.
impl Component for RectangleCollider2d
Required Components: Transform2d.
A component’s Required Components are inserted whenever it is inserted. Note that this will also insert the required components of the required components, recursively, in depth-first order.
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read moreSource§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read moreimpl Copy for RectangleCollider2d
Source§impl Debug for RectangleCollider2d
impl Debug for RectangleCollider2d
Source§impl PartialEq for RectangleCollider2d
impl PartialEq for RectangleCollider2d
impl StructuralPartialEq for RectangleCollider2d
Auto Trait Implementations§
impl Freeze for RectangleCollider2d
impl RefUnwindSafe for RectangleCollider2d
impl Send for RectangleCollider2d
impl Sync for RectangleCollider2d
impl Unpin for RectangleCollider2d
impl UnsafeUnpin for RectangleCollider2d
impl UnwindSafe for RectangleCollider2d
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<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§fn get_component_ids(
components: &Components,
) -> impl Iterator<Item = Option<ComponentId>>
fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.