Split rigid-bodies and colliders into multiple components
This commit is contained in:
@@ -9,12 +9,15 @@ struct OneWayPlatformHook {
|
||||
platform2: ColliderHandle,
|
||||
}
|
||||
|
||||
impl PhysicsHooks for OneWayPlatformHook {
|
||||
impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
||||
fn active_hooks(&self) -> PhysicsHooksFlags {
|
||||
PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS
|
||||
}
|
||||
|
||||
fn modify_solver_contacts(&self, context: &mut ContactModificationContext) {
|
||||
fn modify_solver_contacts(
|
||||
&self,
|
||||
context: &mut ContactModificationContext<RigidBodySet, ColliderSet>,
|
||||
) {
|
||||
// The allowed normal for the first platform is its local +y axis, and the
|
||||
// allowed normal for the second platform is its local -y axis.
|
||||
//
|
||||
@@ -29,16 +32,16 @@ impl PhysicsHooks for OneWayPlatformHook {
|
||||
// - If context.collider_handle2 == self.platform2 then the allowed normal -y needs to be flipped to +y.
|
||||
let mut allowed_local_n1 = Vector2::zeros();
|
||||
|
||||
if context.collider_handle1 == self.platform1 {
|
||||
if context.collider1 == self.platform1 {
|
||||
allowed_local_n1 = Vector2::y();
|
||||
} else if context.collider_handle2 == self.platform1 {
|
||||
} else if context.collider2 == self.platform1 {
|
||||
// Flip the allowed direction.
|
||||
allowed_local_n1 = -Vector2::y();
|
||||
}
|
||||
|
||||
if context.collider_handle1 == self.platform2 {
|
||||
if context.collider1 == self.platform2 {
|
||||
allowed_local_n1 = -Vector2::y();
|
||||
} else if context.collider_handle2 == self.platform2 {
|
||||
} else if context.collider2 == self.platform2 {
|
||||
// Flip the allowed direction.
|
||||
allowed_local_n1 = Vector2::y();
|
||||
}
|
||||
@@ -47,13 +50,12 @@ impl PhysicsHooks for OneWayPlatformHook {
|
||||
context.update_as_oneway_platform(&allowed_local_n1, 0.1);
|
||||
|
||||
// Set the surface velocity of the accepted contacts.
|
||||
let tangent_velocity = if context.collider_handle1 == self.platform1
|
||||
|| context.collider_handle2 == self.platform2
|
||||
{
|
||||
-12.0
|
||||
} else {
|
||||
12.0
|
||||
};
|
||||
let tangent_velocity =
|
||||
if context.collider1 == self.platform1 || context.collider2 == self.platform2 {
|
||||
-12.0
|
||||
} else {
|
||||
12.0
|
||||
};
|
||||
|
||||
for contact in context.solver_contacts.iter_mut() {
|
||||
contact.tangent_velocity.x = tangent_velocity;
|
||||
@@ -115,13 +117,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
}
|
||||
}
|
||||
|
||||
physics.bodies.foreach_active_dynamic_body_mut(|_, body| {
|
||||
for handle in physics.islands.active_dynamic_bodies() {
|
||||
let body = &mut physics.bodies[*handle];
|
||||
if body.position().translation.y > 1.0 {
|
||||
body.set_gravity_scale(1.0, false);
|
||||
} else if body.position().translation.y < -1.0 {
|
||||
body.set_gravity_scale(-1.0, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user