pub struct Collider {
pub raw: SharedShape,
/* private fields */
}
Expand description
A geometric entity that can be attached to a RigidBody
so it can be affected by contacts
and intersection queries.
Related components:
Fields§
§raw: SharedShape
The raw shape from Rapier.
Implementations§
Source§impl Collider
impl Collider
Sourcepub fn promote_scaled_shape(&mut self)
pub fn promote_scaled_shape(&mut self)
This replaces the unscaled version of this collider by its scaled version,
and resets self.scale()
to 1.0
.
Sourcepub fn compound(shapes: Vec<(Vect, Rot, Collider)>) -> Self
pub fn compound(shapes: Vec<(Vect, Rot, Collider)>) -> Self
Initialize a new collider with a compound shape.
Sourcepub fn ball(radius: Real) -> Self
pub fn ball(radius: Real) -> Self
Initialize a new collider with a ball shape defined by its radius.
Sourcepub fn halfspace(outward_normal: Vect) -> Option<Self>
pub fn halfspace(outward_normal: Vect) -> Option<Self>
Initialize a new collider build with a half-space shape defined by the outward normal of its planar boundary.
Sourcepub fn cuboid(half_x: Real, half_y: Real) -> Self
pub fn cuboid(half_x: Real, half_y: Real) -> Self
Initialize a new collider with a cuboid shape defined by its half-extents.
Sourcepub fn round_cuboid(half_x: Real, half_y: Real, border_radius: Real) -> Self
pub fn round_cuboid(half_x: Real, half_y: Real, border_radius: Real) -> Self
Initialize a new collider with a round cuboid shape defined by its half-extents and border radius.
Sourcepub fn capsule(start: Vect, end: Vect, radius: Real) -> Self
pub fn capsule(start: Vect, end: Vect, radius: Real) -> Self
Initialize a new collider with a capsule shape.
Sourcepub fn capsule_x(half_height: Real, radius: Real) -> Self
pub fn capsule_x(half_height: Real, radius: Real) -> Self
Initialize a new collider with a capsule shape aligned with the x
axis.
Sourcepub fn capsule_y(half_height: Real, radius: Real) -> Self
pub fn capsule_y(half_height: Real, radius: Real) -> Self
Initialize a new collider with a capsule shape aligned with the y
axis.
Sourcepub fn triangle(a: Vect, b: Vect, c: Vect) -> Self
pub fn triangle(a: Vect, b: Vect, c: Vect) -> Self
Initializes a collider with a triangle shape.
Sourcepub fn round_triangle(a: Vect, b: Vect, c: Vect, border_radius: Real) -> Self
pub fn round_triangle(a: Vect, b: Vect, c: Vect, border_radius: Real) -> Self
Initializes a collider with a triangle shape with round corners.
Sourcepub fn polyline(vertices: Vec<Vect>, indices: Option<Vec<[u32; 2]>>) -> Self
pub fn polyline(vertices: Vec<Vect>, indices: Option<Vec<[u32; 2]>>) -> Self
Initializes a collider with a polyline shape defined by its vertex and index buffers.
Sourcepub fn trimesh(
vertices: Vec<Vect>,
indices: Vec<[u32; 3]>,
) -> Result<Self, TriMeshBuilderError>
pub fn trimesh( vertices: Vec<Vect>, indices: Vec<[u32; 3]>, ) -> Result<Self, TriMeshBuilderError>
Initializes a collider with a triangle mesh shape defined by its vertex and index buffers.
Sourcepub fn trimesh_with_flags(
vertices: Vec<Vect>,
indices: Vec<[u32; 3]>,
flags: TriMeshFlags,
) -> Result<Self, TriMeshBuilderError>
pub fn trimesh_with_flags( vertices: Vec<Vect>, indices: Vec<[u32; 3]>, flags: TriMeshFlags, ) -> Result<Self, TriMeshBuilderError>
Initializes a collider with a triangle mesh shape defined by its vertex and index buffers, and flags controlling its pre-processing.
Sourcepub fn convex_decomposition(vertices: &[Vect], indices: &[[u32; 2]]) -> Self
pub fn convex_decomposition(vertices: &[Vect], indices: &[[u32; 2]]) -> Self
Initializes a collider with a compound shape obtained from the decomposition of the given trimesh (in 3D) or polyline (in 2D) into convex parts.
Sourcepub fn round_convex_decomposition(
vertices: &[Vect],
indices: &[[u32; 2]],
border_radius: Real,
) -> Self
pub fn round_convex_decomposition( vertices: &[Vect], indices: &[[u32; 2]], border_radius: Real, ) -> Self
Initializes a collider with a compound shape obtained from the decomposition of the given trimesh (in 3D) or polyline (in 2D) into convex parts dilated with round corners.
Sourcepub fn convex_decomposition_with_params(
vertices: &[Vect],
indices: &[[u32; 2]],
params: &VHACDParameters,
) -> Self
pub fn convex_decomposition_with_params( vertices: &[Vect], indices: &[[u32; 2]], params: &VHACDParameters, ) -> Self
Initializes a collider with a compound shape obtained from the decomposition of the given trimesh (in 3D) or polyline (in 2D) into convex parts.
Sourcepub fn round_convex_decomposition_with_params(
vertices: &[Vect],
indices: &[[u32; 2]],
params: &VHACDParameters,
border_radius: Real,
) -> Self
pub fn round_convex_decomposition_with_params( vertices: &[Vect], indices: &[[u32; 2]], params: &VHACDParameters, border_radius: Real, ) -> Self
Initializes a collider with a compound shape obtained from the decomposition of the given trimesh (in 3D) or polyline (in 2D) into convex parts dilated with round corners.
Sourcepub fn convex_hull(points: &[Vect]) -> Option<Self>
pub fn convex_hull(points: &[Vect]) -> Option<Self>
Initializes a new collider with a 2D convex polygon or 3D convex polyhedron obtained after computing the convex-hull of the given points.
Sourcepub fn round_convex_hull(points: &[Vect], border_radius: Real) -> Option<Self>
pub fn round_convex_hull(points: &[Vect], border_radius: Real) -> Option<Self>
Initializes a new collider with a round 2D convex polygon or 3D convex polyhedron
obtained after computing the convex-hull of the given points. The shape is dilated
by a sphere of radius border_radius
.
Sourcepub fn convex_polyline(points: Vec<Vect>) -> Option<Self>
pub fn convex_polyline(points: Vec<Vect>) -> Option<Self>
Creates a new collider that is a convex polygon formed by the given polyline assumed to be convex (no convex-hull will be automatically computed).
Sourcepub fn round_convex_polyline(
points: Vec<Vect>,
border_radius: Real,
) -> Option<Self>
pub fn round_convex_polyline( points: Vec<Vect>, border_radius: Real, ) -> Option<Self>
Creates a new collider that is a round convex polygon formed by the
given polyline assumed to be convex (no convex-hull will be automatically
computed). The polygon shape is dilated by a sphere of radius border_radius
.
Sourcepub fn heightfield(heights: Vec<Real>, scale: Vect) -> Self
pub fn heightfield(heights: Vec<Real>, scale: Vect) -> Self
Initializes a collider with a heightfield shape defined by its set of height and a scale factor along each coordinate axis.
Sourcepub fn as_typed_shape(&self) -> ColliderView<'_>
pub fn as_typed_shape(&self) -> ColliderView<'_>
Takes a strongly typed reference of this collider.
Sourcepub fn as_unscaled_typed_shape(&self) -> ColliderView<'_>
pub fn as_unscaled_typed_shape(&self) -> ColliderView<'_>
Takes a strongly typed reference of the unscaled version of this collider.
Sourcepub fn as_cuboid(&self) -> Option<CuboidView<'_>>
pub fn as_cuboid(&self) -> Option<CuboidView<'_>>
Downcast this collider to a cuboid, if it is one.
Sourcepub fn as_capsule(&self) -> Option<CapsuleView<'_>>
pub fn as_capsule(&self) -> Option<CapsuleView<'_>>
Downcast this collider to a capsule, if it is one.
Sourcepub fn as_segment(&self) -> Option<SegmentView<'_>>
pub fn as_segment(&self) -> Option<SegmentView<'_>>
Downcast this collider to a segment, if it is one.
Sourcepub fn as_triangle(&self) -> Option<TriangleView<'_>>
pub fn as_triangle(&self) -> Option<TriangleView<'_>>
Downcast this collider to a triangle, if it is one.
Sourcepub fn as_trimesh(&self) -> Option<TriMeshView<'_>>
pub fn as_trimesh(&self) -> Option<TriMeshView<'_>>
Downcast this collider to a triangle mesh, if it is one.
Sourcepub fn as_polyline(&self) -> Option<PolylineView<'_>>
pub fn as_polyline(&self) -> Option<PolylineView<'_>>
Downcast this collider to a polyline, if it is one.
Sourcepub fn as_halfspace(&self) -> Option<HalfSpaceView<'_>>
pub fn as_halfspace(&self) -> Option<HalfSpaceView<'_>>
Downcast this collider to a half-space, if it is one.
Sourcepub fn as_heightfield(&self) -> Option<HeightFieldView<'_>>
pub fn as_heightfield(&self) -> Option<HeightFieldView<'_>>
Downcast this collider to a heightfield, if it is one.
Sourcepub fn as_compound(&self) -> Option<CompoundView<'_>>
pub fn as_compound(&self) -> Option<CompoundView<'_>>
Downcast this collider to a compound shape, if it is one.
Sourcepub fn as_convex_polygon(&self) -> Option<ConvexPolygonView<'_>>
pub fn as_convex_polygon(&self) -> Option<ConvexPolygonView<'_>>
Downcast this collider to a convex polygon, if it is one.
Sourcepub fn as_ball_mut(&mut self) -> Option<BallViewMut<'_>>
pub fn as_ball_mut(&mut self) -> Option<BallViewMut<'_>>
Downcast this collider to a mutable ball, if it is one.
Sourcepub fn as_cuboid_mut(&mut self) -> Option<CuboidViewMut<'_>>
pub fn as_cuboid_mut(&mut self) -> Option<CuboidViewMut<'_>>
Downcast this collider to a mutable cuboid, if it is one.
Sourcepub fn as_capsule_mut(&mut self) -> Option<CapsuleViewMut<'_>>
pub fn as_capsule_mut(&mut self) -> Option<CapsuleViewMut<'_>>
Downcast this collider to a mutable capsule, if it is one.
Sourcepub fn as_segment_mut(&mut self) -> Option<SegmentViewMut<'_>>
pub fn as_segment_mut(&mut self) -> Option<SegmentViewMut<'_>>
Downcast this collider to a mutable segment, if it is one.
Sourcepub fn as_triangle_mut(&mut self) -> Option<TriangleViewMut<'_>>
pub fn as_triangle_mut(&mut self) -> Option<TriangleViewMut<'_>>
Downcast this collider to a mutable triangle, if it is one.
Sourcepub fn as_trimesh_mut(&mut self) -> Option<TriMeshViewMut<'_>>
pub fn as_trimesh_mut(&mut self) -> Option<TriMeshViewMut<'_>>
Downcast this collider to a mutable triangle mesh, if it is one.
Sourcepub fn as_polyline_mut(&mut self) -> Option<PolylineViewMut<'_>>
pub fn as_polyline_mut(&mut self) -> Option<PolylineViewMut<'_>>
Downcast this collider to a mutable polyline, if it is one.
Sourcepub fn as_halfspace_mut(&mut self) -> Option<HalfSpaceViewMut<'_>>
pub fn as_halfspace_mut(&mut self) -> Option<HalfSpaceViewMut<'_>>
Downcast this collider to a mutable half-space, if it is one.
Sourcepub fn as_heightfield_mut(&mut self) -> Option<HeightFieldViewMut<'_>>
pub fn as_heightfield_mut(&mut self) -> Option<HeightFieldViewMut<'_>>
Downcast this collider to a mutable heightfield, if it is one.
Sourcepub fn set_scale(&mut self, scale: Vect, num_subdivisions: u32)
pub fn set_scale(&mut self, scale: Vect, num_subdivisions: u32)
Set the scaling factor of this shape.
If the scaling factor is non-uniform, and the scaled shape can’t be
represented as a supported smooth shape (for example scalling a Ball
with a non-uniform scale results in an ellipse which isn’t supported),
the shape is approximated by a convex polygon/convex polyhedron using
num_subdivisions
subdivisions.
Sourcepub fn project_local_point_with_max_dist(
&self,
point: Vect,
solid: bool,
max_dist: Real,
) -> Option<PointProjection>
pub fn project_local_point_with_max_dist( &self, point: Vect, solid: bool, max_dist: Real, ) -> Option<PointProjection>
Projects a point on self
, unless the projection lies further than the given max distance.
The point is assumed to be expressed in the local-space of self
.
Sourcepub fn project_point_with_max_dist(
&self,
translation: Vect,
rotation: Rot,
point: Vect,
solid: bool,
max_dist: Real,
) -> Option<PointProjection>
pub fn project_point_with_max_dist( &self, translation: Vect, rotation: Rot, point: Vect, solid: bool, max_dist: Real, ) -> Option<PointProjection>
Projects a point on self
transformed by m
, unless the projection lies further than the given max distance.
Sourcepub fn project_local_point(&self, point: Vect, solid: bool) -> PointProjection
pub fn project_local_point(&self, point: Vect, solid: bool) -> PointProjection
Projects a point on self
.
The point is assumed to be expressed in the local-space of self
.
Sourcepub fn project_local_point_and_get_feature(
&self,
point: Vect,
) -> (PointProjection, FeatureId)
pub fn project_local_point_and_get_feature( &self, point: Vect, ) -> (PointProjection, FeatureId)
Projects a point on the boundary of self
and returns the id of the
feature the point was projected on.
Sourcepub fn distance_to_local_point(&self, point: Vect, solid: bool) -> Real
pub fn distance_to_local_point(&self, point: Vect, solid: bool) -> Real
Computes the minimal distance between a point and self
.
Sourcepub fn contains_local_point(&self, point: Vect) -> bool
pub fn contains_local_point(&self, point: Vect) -> bool
Tests if the given point is inside of self
.
Sourcepub fn project_point(
&self,
translation: Vect,
rotation: Rot,
point: Vect,
solid: bool,
) -> PointProjection
pub fn project_point( &self, translation: Vect, rotation: Rot, point: Vect, solid: bool, ) -> PointProjection
Projects a point on self
transformed by m
.
Sourcepub fn distance_to_point(
&self,
translation: Vect,
rotation: Rot,
point: Vect,
solid: bool,
) -> Real
pub fn distance_to_point( &self, translation: Vect, rotation: Rot, point: Vect, solid: bool, ) -> Real
Computes the minimal distance between a point and self
transformed by m
.
Sourcepub fn project_point_and_get_feature(
&self,
translation: Vect,
rotation: Rot,
point: Vect,
) -> (PointProjection, FeatureId)
pub fn project_point_and_get_feature( &self, translation: Vect, rotation: Rot, point: Vect, ) -> (PointProjection, FeatureId)
Projects a point on the boundary of self
transformed by m
and returns the id of the
feature the point was projected on.
Sourcepub fn contains_point(
&self,
translation: Vect,
rotation: Rot,
point: Vect,
) -> bool
pub fn contains_point( &self, translation: Vect, rotation: Rot, point: Vect, ) -> bool
Tests if the given point is inside of self
transformed by m
.
Sourcepub fn cast_local_ray(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_time_of_impact: Real,
solid: bool,
) -> Option<Real>
pub fn cast_local_ray( &self, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, solid: bool, ) -> Option<Real>
Computes the time of impact between this transform shape and a ray.
Sourcepub fn cast_local_ray_and_get_normal(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_time_of_impact: Real,
solid: bool,
) -> Option<RayIntersection>
pub fn cast_local_ray_and_get_normal( &self, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, solid: bool, ) -> Option<RayIntersection>
Computes the time of impact, and normal between this transformed shape and a ray.
Sourcepub fn intersects_local_ray(
&self,
ray_origin: Vect,
ray_dir: Vect,
max_time_of_impact: Real,
) -> bool
pub fn intersects_local_ray( &self, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, ) -> bool
Tests whether a ray intersects this transformed shape.
Sourcepub fn cast_ray(
&self,
translation: Vect,
rotation: Rot,
ray_origin: Vect,
ray_dir: Vect,
max_time_of_impact: Real,
solid: bool,
) -> Option<Real>
pub fn cast_ray( &self, translation: Vect, rotation: Rot, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, solid: bool, ) -> Option<Real>
Computes the time of impact between this transform shape and a ray.
Sourcepub fn cast_ray_and_get_normal(
&self,
translation: Vect,
rotation: Rot,
ray_origin: Vect,
ray_dir: Vect,
max_time_of_impact: Real,
solid: bool,
) -> Option<RayIntersection>
pub fn cast_ray_and_get_normal( &self, translation: Vect, rotation: Rot, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, solid: bool, ) -> Option<RayIntersection>
Computes the time of impact, and normal between this transformed shape and a ray.
Trait Implementations§
Source§impl Component for Collider
impl Component for Collider
Source§const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table
Source§fn register_required_components(
requiree: ComponentId,
components: &mut Components,
storages: &mut Storages,
required_components: &mut RequiredComponents,
inheritance_depth: u16,
)
fn register_required_components( requiree: ComponentId, components: &mut Components, storages: &mut Storages, required_components: &mut RequiredComponents, inheritance_depth: u16, )
Source§fn register_component_hooks(hooks: &mut ComponentHooks)
fn register_component_hooks(hooks: &mut ComponentHooks)
ComponentHooks
.Source§fn from(shared_shape: SharedShape) -> Collider
fn from(shared_shape: SharedShape) -> 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 !UnwindSafe for Collider
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> 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
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
Source§fn register_required_components(
components: &mut Components,
storages: &mut Storages,
required_components: &mut RequiredComponents,
)
fn register_required_components( components: &mut Components, storages: &mut Storages, required_components: &mut RequiredComponents, )
Bundle
.Source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using default()
.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.