Trait bevy_rapier2d::prelude::PhysicsHooks[][src]

pub trait PhysicsHooks<Bodies, Colliders>: Send + Sync {
    fn filter_contact_pair(
        &self,
        _context: &PairFilterContext<'_, Bodies, Colliders>
    ) -> Option<SolverFlags> { ... }
fn filter_intersection_pair(
        &self,
        _context: &PairFilterContext<'_, Bodies, Colliders>
    ) -> bool { ... }
fn modify_solver_contacts(
        &self,
        _context: &mut ContactModificationContext<'_, Bodies, Colliders>
    ) { ... } }
Expand description

User-defined functions called by the physics engines during one timestep in order to customize its behavior.

Provided methods

fn filter_contact_pair(
    &self,
    _context: &PairFilterContext<'_, Bodies, Colliders>
) -> Option<SolverFlags>
[src]

Applies the contact pair filter.

Note that this method will only be called if at least one of the colliders involved in the contact contains the ActiveHooks::FILTER_CONTACT_PAIRS flags in its physics hooks flags.

User-defined filter for potential contact pairs detected by the broad-phase. This can be used to apply custom logic in order to decide whether two colliders should have their contact computed by the narrow-phase, and if these contact should be solved by the constraints solver

Note that using a contact pair filter will replace the default contact filtering which consists of preventing contact computation between two non-dynamic bodies.

This filtering method is called after taking into account the colliders collision groups.

If this returns None, then the narrow-phase will ignore this contact pair and not compute any contact manifolds for it. If this returns Some, then the narrow-phase will compute contact manifolds for this pair of colliders, and configure them with the returned solver flags. For example, if this returns Some(SolverFlags::COMPUTE_IMPULSES) then the contacts will be taken into account by the constraints solver. If this returns Some(SolverFlags::empty()) then the constraints solver will ignore these contacts.

fn filter_intersection_pair(
    &self,
    _context: &PairFilterContext<'_, Bodies, Colliders>
) -> bool
[src]

Applies the intersection pair filter.

Note that this method will only be called if at least one of the colliders involved in the contact contains the ActiveHooks::FILTER_INTERSECTION_PAIR flags in its physics hooks flags.

User-defined filter for potential intersection pairs detected by the broad-phase.

This can be used to apply custom logic in order to decide whether two colliders should have their intersection computed by the narrow-phase.

Note that using an intersection pair filter will replace the default intersection filtering which consists of preventing intersection computation between two non-dynamic bodies.

This filtering method is called after taking into account the colliders collision groups.

If this returns false, then the narrow-phase will ignore this pair and not compute any intersection information for it. If this return true then the narrow-phase will compute intersection information for this pair.

fn modify_solver_contacts(
    &self,
    _context: &mut ContactModificationContext<'_, Bodies, Colliders>
)
[src]

Modifies the set of contacts seen by the constraints solver.

Note that this method will only be called if at least one of the colliders involved in the contact contains the ActiveHooks::MODIFY_SOLVER_CONTACTS flags in its physics hooks flags.

By default, the content of solver_contacts is computed from manifold.points. This method will be called on each contact manifold which have the flag SolverFlags::modify_solver_contacts set. This method can be used to modify the set of solver contacts seen by the constraints solver: contacts can be removed and modified.

Note that if all the contacts have to be ignored by the constraint solver, you may simply do context.solver_contacts.clear().

Modifying the solver contacts allow you to achieve various effects, including:

  • Simulating conveyor belts by setting the surface_velocity of a solver contact.
  • Simulating shapes with multiply materials by modifying the friction and restitution coefficient depending of the features in contacts.
  • Simulating one-way platforms depending on the contact normal.

Each contact manifold is given a u32 user-defined data that is persistent between timesteps (as long as the contact manifold exists). This user-defined data is initialized as 0 and can be modified in context.user_data.

The world-space contact normal can be modified in context.normal.

Implementations on Foreign Types

impl<Bodies, Colliders> PhysicsHooks<Bodies, Colliders> for ()[src]

pub fn filter_contact_pair(
    &self,
    _context: &PairFilterContext<'_, Bodies, Colliders>
) -> Option<SolverFlags>
[src]

pub fn filter_intersection_pair(
    &self,
    &PairFilterContext<'_, Bodies, Colliders>
) -> bool
[src]

pub fn modify_solver_contacts(
    &self,
    &mut ContactModificationContext<'_, Bodies, Colliders>
)
[src]

Implementors