Open
Description
Contact graph reports NaN or 0 for tangent_impulse when a frictional contact occurs between a capsule and a rectangle or 2 rects. Have not investigated other combinations of shapes, but I imagine this is not isolated to those cases?
thank you for Rapier!
repro code:
A test example:
use std::f32::consts::PI;
use rapier2d::prelude::*;
use rapier_testbed2d::Testbed;
pub fn init_world(testbed: &mut Testbed) {
/*
* World
*/
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new();
/*
* The ground
*/
let ground_size = 20.0;
let ground_height = 1.0;
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -3.0]);
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height)
.rotation(0.25 * PI)
.friction(0.9);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* A tilted capsule that cannot rotate.
*/
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![0.0, 4.0])
.lock_rotations();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_y(2.0, 1.0).friction(0.9);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(point![0.0, 0.0], 10.0);
}
change to enable printing in src_testbed/testbed.rs, line 1430
if harness.state.timestep_id % 100 == 0 {
let pairs: Vec<_> = harness.physics.narrow_phase.contact_pairs().collect();
println!("contact pairs: {:?}", pairs);
}
quick debug impl for ContactPair in src/geometry/contact_pair.rs, line 133
impl std::fmt::Debug for ContactPair {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ContactPair")
.field("collider1", &self.collider1)
.field("collider2", &self.collider2)
.field("manifolds", &self.manifolds)
.field("has_any_active_contact", &self.has_any_active_contact)
.finish()
}
}
full print output (note tangent_impulse values)
[
ContactPair {
collider1: ColliderHandle(Index { index: 0, generation: 0 }),
collider2: ColliderHandle(Index { index: 1, generation: 0 }),
manifolds: [
ContactManifold {
points: [
TrackedContact {
local_p1: [4.0150623, 1.0],
local_p2: [0.70710677, 1.2928929],
dist: 2.827232,
fid1: PackedFeatureId(3221225524),
fid2: PackedFeatureId(1073741826),
data: ContactData {
impulse: 0.0,
tangent_impulse: [[0.0]],
warmstart_impulse: 0.0,
warmstart_tangent_impulse: [[0.0]]
}
},
TrackedContact {
local_p1: [1.186636, 1.0],
local_p2: [0.70710677, -2.7071066],
dist: -0.0011950731,
fid1: PackedFeatureId(3221225524),
fid2: PackedFeatureId(1073741824),
data: ContactData {
impulse: 1.610124,
tangent_impulse: [[NaN]],
warmstart_impulse: 0.3220248,
warmstart_tangent_impulse: [[-0.2898223]]
}
}
],
local_n1: [[-0.0, 1.0]],
local_n2: [[0.70710677, -0.70710677]],
subshape1: 0,
subshape2: 0,
subshape_pos1: None,
subshape_pos2: None,
data: ContactManifoldData {
rigid_body1: Some(RigidBodyHandle(Index { index: 0, generation: 0 })),
rigid_body2: Some(RigidBodyHandle(Index { index: 1, generation: 0 })),
solver_flags: SolverFlags(COMPUTE_IMPULSES),
normal: [[-0.70710677, 0.70710677]],
solver_contacts: [SolverContact {
contact_id: 1,
point: [0.13239408, -1.4542375],
dist: -0.0011950731,
friction: 0.9,
restitution: 0.0,
tangent_velocity: [[0.0, 0.0]],
is_new: false,
warmstart_impulse: 0.3220248,
warmstart_tangent_impulse: [[-0.2898223]]
}],
relative_dominance: 128,
user_data: 0
}
}
],
has_any_active_contact: true
}
]