Struct jumpy::core::physics::collisions::CollisionWorld
source · pub struct CollisionWorld<'a> {
pub entities: Res<'a, Entities>,
pub ctx: ResMutInit<'a, RapierContext>,
pub actors: CompMut<'a, Actor>,
pub solids: CompMut<'a, Solid>,
pub colliders: CompMut<'a, Collider>,
pub tile_rapier_handles: CompMut<'a, TileRapierHandle>,
pub tile_layers: Comp<'a, TileLayer>,
pub tile_collision_kinds: Comp<'a, TileCollisionKind>,
pub tile_dynamic_colliders: Comp<'a, TileDynamicCollider>,
pub spawned_map_layer_metas: Comp<'a, SpawnedMapLayerMeta>,
}Fields§
§entities: Res<'a, Entities>§ctx: ResMutInit<'a, RapierContext>The rapier context.
actors: CompMut<'a, Actor>Actors are things like players that move around and detect collisions, but don’t collide with other actors.
solids: CompMut<'a, Solid>Solids are things like walls and platforms, that aren’t tiles, that have solid collisions.
colliders: CompMut<'a, Collider>A collider is anything that can detect collisions in the world other than tiles, and
must either be an Actor or Solid to participate in collision detection.
tile_rapier_handles: CompMut<'a, TileRapierHandle>Contains the rapier collider handles for each map tile.
tile_layers: Comp<'a, TileLayer>§tile_collision_kinds: Comp<'a, TileCollisionKind>§tile_dynamic_colliders: Comp<'a, TileDynamicCollider>§spawned_map_layer_metas: Comp<'a, SpawnedMapLayerMeta>Implementations§
source§impl<'a> CollisionWorld<'a>
impl<'a> CollisionWorld<'a>
sourcepub fn set_actor_shape(&mut self, entity: Entity, shape: ColliderShape)
pub fn set_actor_shape(&mut self, entity: Entity, shape: ColliderShape)
Update shape of actor’s Collider. Warns if entity does not have an Actor component.
Updates shape on Collider and rebuilds rapier’s collider on rigidbody.
Use Self::set_actor_shape_from_builder for more control over new collider’s settings.
sourcepub fn set_actor_shape_from_builder(
&mut self,
entity: Entity,
collider_builder: ColliderBuilder,
shape: ColliderShape,
)
pub fn set_actor_shape_from_builder( &mut self, entity: Entity, collider_builder: ColliderBuilder, shape: ColliderShape, )
Update shape of actor’s Collider. Warns if entity does not have an Actor component.
Updates shape on Collider and rebuilds rapier’s collider on rigidbody.
Accepts a rapier::ColliderBuilder (can get one with build_actor_rapier_collider) so
other settings may be configured on new collider.
sourcepub fn mutate_rigidbody(
&mut self,
entity: Entity,
command: impl FnOnce(&mut RigidBody),
) -> Result<(), PhysicsError>
pub fn mutate_rigidbody( &mut self, entity: Entity, command: impl FnOnce(&mut RigidBody), ) -> Result<(), PhysicsError>
Call closure with mutable reference to rapier::RigidBody for entity.
§Errors
PhysicsError::BodyNotInitializedwhen called before physics is updated to initialize body after aCollidercomponent is newly added. (If missing collider or rapier handle does not map to body).
source§impl<'a> CollisionWorld<'a>
impl<'a> CollisionWorld<'a>
sourcepub fn update(
&mut self,
dt: f32,
physics_params: PhysicsParams,
transforms: &mut CompMut<'_, Transform>,
dynamic_bodies: &mut CompMut<'_, DynamicBody>,
)
pub fn update( &mut self, dt: f32, physics_params: PhysicsParams, transforms: &mut CompMut<'_, Transform>, dynamic_bodies: &mut CompMut<'_, DynamicBody>, )
Updates the collision world with the entity’s actual transforms. Advance physics, synchronize position of dynamic bodies.
If the transform of an entity is changed without calling update(), then collision queries
will be out-of-date with the actual entity positions.
⚠️ Warning: This does not update the map tile collisions. To do that, call
update_tiles()instead.
sourcepub fn sync_bodies<'b, Tq>(
&mut self,
transforms: Tq,
dynamic_bodies: &mut CompMut<'_, DynamicBody>,
)
pub fn sync_bodies<'b, Tq>( &mut self, transforms: Tq, dynamic_bodies: &mut CompMut<'_, DynamicBody>, )
Sync the transforms and attributes ( like disabled ) of the colliders.
Creates rapier bodies for any object with collision.
Handle DynamicBody toggling between simulation and kinematic mode.
sourcefn apply_simulation_commands<'b, Dq>(&mut self, dynamic_bodies: Dq)
fn apply_simulation_commands<'b, Dq>(&mut self, dynamic_bodies: Dq)
Apply simulation commands to dynamic bodies.
§Panics
This should be called after bodies are initialized, DynamicBody must have
a Collider with valid rapier::RigidBodyHandle otherwise will panic.
sourcepub fn update_tiles(&mut self)
pub fn update_tiles(&mut self)
Update all of the map tile collisions.
You should only need to call this when spawning or otherwise completely rebuilding the map layout.
sourcepub fn update_tile(&mut self, layer_idx: u32, pos: UVec2)
pub fn update_tile(&mut self, layer_idx: u32, pos: UVec2)
Update the collision for the tile with the given layer index and map grid position.
sourcepub fn update_tiles_with_filter<F>(&mut self, filter: F)
pub fn update_tiles_with_filter<F>(&mut self, filter: F)
Update the collisions for map tiles that pass the given filter.
The filter is a function that takes the layer index and the tile position as an argument.
sourcepub fn handle_teleport(&mut self, entity: Entity)
pub fn handle_teleport(&mut self, entity: Entity)
When spawning or teleporting an entity, this should be called to make sure the entity doesn’t get stuck in semi-solid platforms, and properly falls out of them if it happens to be colliding with one when spawned.
sourcepub fn actor_collisions(&self, entity: Entity) -> Vec<Entity>
pub fn actor_collisions(&self, entity: Entity) -> Vec<Entity>
Returns the collisions that one actor has with any other actors.
sourcepub fn actor_collisions_filtered(
&self,
entity: Entity,
filter: impl Fn(Entity) -> bool,
) -> Vec<Entity>
pub fn actor_collisions_filtered( &self, entity: Entity, filter: impl Fn(Entity) -> bool, ) -> Vec<Entity>
Returns the collisions that one actor has with any other actors filtered by the given Fn
sourcepub fn descent(&mut self, entity: Entity)
pub fn descent(&mut self, entity: Entity)
Put the entity’s collider into descent mode so that it will fall through jump-through platforms.
sourcepub fn move_vertical(
&mut self,
transforms: &mut CompMut<'_, Transform>,
entity: Entity,
dy: f32,
) -> bool
pub fn move_vertical( &mut self, transforms: &mut CompMut<'_, Transform>, entity: Entity, dy: f32, ) -> bool
Attempt to move a body vertically. This will return true if an obstacle was run into that
caused the movement to stop short.
sourcepub fn move_horizontal(
&mut self,
transforms: &mut CompMut<'_, Transform>,
entity: Entity,
dx: f32,
) -> bool
pub fn move_horizontal( &mut self, transforms: &mut CompMut<'_, Transform>, entity: Entity, dx: f32, ) -> bool
Attempt to move a body horizontally. This will return true if an obstacle was run into
that caused the movement to stop short.
sourcepub fn solid_at(&self, pos: Vec2) -> bool
pub fn solid_at(&self, pos: Vec2) -> bool
Returns whether or not there is a tile or solid at the given position.
⚠️ Warning: There is a slight difference to how
tile_collision_pointandtile_collisionreports collisions.
tile_collisionwill report a collision if the collider shape is perfectly lined up along the edge of a tile, buttile_collision_pointwon’t.
pub fn solid_collision_point(&self, pos: Vec2) -> bool
sourcepub fn tile_collision_point(&self, pos: Vec2) -> TileCollisionKind
pub fn tile_collision_point(&self, pos: Vec2) -> TileCollisionKind
Returns the tile collision at the given point.
⚠️ Warning: There is a slight difference to how
tile_collision_pointandtile_collisionreports collisions.
tile_collisionwill report a collision if the collider shape is perfectly lined up along the edge of a tile, buttile_collision_pointwon’t.
sourcepub fn tile_collision(
&self,
transform: Transform,
shape: ColliderShape,
) -> TileCollisionKind
pub fn tile_collision( &self, transform: Transform, shape: ColliderShape, ) -> TileCollisionKind
Get the TileCollisionKind of the first tile detected colliding with the shape at the
given transform.
pub fn tile_collision_filtered( &self, transform: Transform, shape: ColliderShape, filter: impl Fn(Entity) -> bool, ) -> TileCollisionKind
sourcepub fn get_collider(&self, actor: Entity) -> &Collider
pub fn get_collider(&self, actor: Entity) -> &Collider
Get the collider for the given entity.
Trait Implementations§
source§impl<'a> SystemParam for CollisionWorld<'a>
impl<'a> SystemParam for CollisionWorld<'a>
§type State = (<Res<'a, Entities> as SystemParam>::State, <ResMutInit<'a, RapierContext> as SystemParam>::State, <RefMut<'a, ComponentStore<Actor>> as SystemParam>::State, <RefMut<'a, ComponentStore<Solid>> as SystemParam>::State, <RefMut<'a, ComponentStore<Collider>> as SystemParam>::State, <RefMut<'a, ComponentStore<TileRapierHandle>> as SystemParam>::State, <Ref<'a, ComponentStore<TileLayer>> as SystemParam>::State, <Ref<'a, ComponentStore<TileCollisionKind>> as SystemParam>::State, <Ref<'a, ComponentStore<TileDynamicCollider>> as SystemParam>::State, <Ref<'a, ComponentStore<SpawnedMapLayerMeta>> as SystemParam>::State)
type State = (<Res<'a, Entities> as SystemParam>::State, <ResMutInit<'a, RapierContext> as SystemParam>::State, <RefMut<'a, ComponentStore<Actor>> as SystemParam>::State, <RefMut<'a, ComponentStore<Solid>> as SystemParam>::State, <RefMut<'a, ComponentStore<Collider>> as SystemParam>::State, <RefMut<'a, ComponentStore<TileRapierHandle>> as SystemParam>::State, <Ref<'a, ComponentStore<TileLayer>> as SystemParam>::State, <Ref<'a, ComponentStore<TileCollisionKind>> as SystemParam>::State, <Ref<'a, ComponentStore<TileDynamicCollider>> as SystemParam>::State, <Ref<'a, ComponentStore<SpawnedMapLayerMeta>> as SystemParam>::State)
§type Param<'p> = CollisionWorld<'p>
type Param<'p> = CollisionWorld<'p>
Auto Trait Implementations§
impl<'a> Freeze for CollisionWorld<'a>
impl<'a> !RefUnwindSafe for CollisionWorld<'a>
impl<'a> Send for CollisionWorld<'a>
impl<'a> Sync for CollisionWorld<'a>
impl<'a> Unpin for CollisionWorld<'a>
impl<'a> !UnwindSafe for CollisionWorld<'a>
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.§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> Conv for T
impl<T> Conv for 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<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoArcAny for T
impl<T> IntoArcAny for T
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 more§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
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.