Skip to main content

Collisions

Struct Collisions 

Source
pub struct Collisions { /* private fields */ }
Expand description

The colliders of the entities that have a Collider and a Transform, in a CollisionWorld: a resource that the engine rebuilds each tick, in the system nadir::movement.

Systems query it through Collisions::world, whose answers are collider indices: Collisions::entity turns them into entities, and Collisions::index an entity into the index to ignore in a cast. The tile grid is set here too.

What it holds during a tick:

  • From nadir::movement on, the colliders of this tick, each moved as its entity moved.
  • nadir::triggers copies every collider’s position from its Transform before it looks for overlaps, so a system that moves an entity in Movement after the engine’s movement, or in PostMovement before nadir::triggers, moves its collider too.
  • After that, and until the next tick’s nadir::movement (in the Input and Gameplay stages, and in frames), it is as the last tick left it. An entity despawned since still answers, and one spawned since is missing: check what Collisions::entity gives with World::is_alive.

Implementations§

Source§

impl Collisions

Source

pub fn new() -> Self

No colliders and an empty tile grid, hashing in cells of CollisionWorld::DEFAULT_CELL_SIZE.

Source

pub fn with_cell_size(cell_size: f32) -> Self

No colliders and an empty tile grid, hashing in cells of cell_size pixels: use at least twice the size of a typical collider. Insert it as a resource to replace the engine’s.

§Panics

If cell_size is not a finite number above 0.

Source

pub fn world(&self) -> &CollisionWorld

The collision world, for queries and casts.

Source

pub fn grid(&self) -> &TileGrid

The tile grid.

Source

pub fn grid_mut(&mut self) -> &mut TileGrid

The tile grid, to change tiles.

Source

pub fn set_grid(&mut self, grid: TileGrid)

Replaces the tile grid.

Source

pub fn entity(&self, index: u32) -> Entity

The entity of collider index, as of the last rebuild. It may have been despawned since (see Collisions).

§Panics

If there is no collider index.

Source

pub fn index(&self, entity: Entity) -> Option<u32>

The index of entity’s collider as of the last rebuild, or None if it had none then.

Trait Implementations§

Source§

impl Default for Collisions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.