pub fn solve_constraint<C: XpbdConstraint<ENTITY_COUNT> + Component, const ENTITY_COUNT: usize>(
commands: Commands<'_, '_>,
bodies: Query<'_, '_, RigidBodyQuery>,
constraints: Query<'_, '_, &mut C, Without<RigidBody>>,
time: Res<'_, Time>
)
Expand description
Iterates through the XPBD constraints of a given type and solves them. Sleeping bodies are woken up when active bodies interact with them in a constraint.
Note that this system only works for constraints that are modeled as entities. If you store constraints in a resource, you must create your own system for solving them.
§User constraints
To create a new constraint, implement XpbdConstraint
for a component, get the SubstepSchedule
and add this system into
the SubstepSolverSet::SolveUserConstraints
set.
You must provide the number of entities in the constraint using generics.
It should look something like this:
ⓘ
let substeps = app
.get_schedule_mut(SubstepSchedule)
.expect("add SubstepSchedule first");
substeps.add_systems(
solve_constraint::<YourConstraint, ENTITY_COUNT>
.in_set(SubstepSolverSet::SolveUserConstraints),
);