Enum rusty_engine::physics::Collider
source · pub enum Collider {
NoCollider,
Poly(Vec<Vec2>),
}
Expand description
Represents the collider (or lack thereof) of a sprite. Two sprites need to have colliders AND
have their Sprite.collision
fields set to true
to generate collision events. See the
collider
example to create your own colliders
Variants§
Implementations§
source§impl Collider
impl Collider
sourcepub fn rect<T: Into<Vec2>>(topleft: T, bottomright: T) -> Self
pub fn rect<T: Into<Vec2>>(topleft: T, bottomright: T) -> Self
Generate a rectangular collider based on top-left and bottom-right points
sourcepub fn poly<T: Into<Vec2> + Copy>(points: &[T]) -> Self
pub fn poly<T: Into<Vec2> + Copy>(points: &[T]) -> Self
Convert a slice of Vec2’s into a polygon collider. This is helpful if you want to hard-code colliders in your code as arrays or vectors of Vec2.
sourcepub fn circle_custom(radius: f32, vertices: usize) -> Self
pub fn circle_custom(radius: f32, vertices: usize) -> Self
Generate a polygon circle approximation with the specified radius and amount of vertices
sourcepub fn circle(radius: f32) -> Self
pub fn circle(radius: f32) -> Self
Generate a 16-vertex polygon circle approximation. 16 was chosen as the default as it works quite well with the circular sprites in the asset pack.
sourcepub fn is_convex(&self) -> bool
pub fn is_convex(&self) -> bool
Whether the points in the collider represent a convex polygon (not concave or complex). This is important, because Rusty Engine’s collision detection doesn’t work correctly unless colliders are convex polygons.
This implementation is based on Rory Daulton’s answer on https://stackoverflow.com/questions/471962/how-do-i-efficiently-determine-if-a-polygon-is-convex-non-convex-or-complex?answertab=votes#tab-top
Trait Implementations§
source§impl<'de> Deserialize<'de> for Collider
impl<'de> Deserialize<'de> for Collider
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for Collider
impl PartialEq for Collider
impl StructuralPartialEq for Collider
Auto Trait Implementations§
impl RefUnwindSafe for Collider
impl Send for Collider
impl Sync for Collider
impl Unpin for Collider
impl UnwindSafe for Collider
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.