fix: collision better
This commit is contained in:
@@ -146,7 +146,7 @@ pub fn render_xpbd_bodies(backend: &mut BevyLinesRenderBackend,
|
||||
| xpbd::constraint::impl_::Constraint::Contact(contact) => {
|
||||
let b = bodies.get(body.handles[contact.idx]).unwrap();
|
||||
let t = b.translation();
|
||||
vec![(color.contact, vec![*t, contact.contact_point])]
|
||||
vec![(color.contact, vec![*t, t + contact.normal.into_inner()])]
|
||||
},
|
||||
})
|
||||
.for_each(|(color, positions)| {
|
||||
|
||||
@@ -157,20 +157,20 @@ pub mod contact {
|
||||
impl Constraint for Contact {
|
||||
fn apply(&mut self, step: &mut crate::xpbd::step::Step) {
|
||||
let b = &mut step.bodies[self.idx];
|
||||
let vmax = 10.0; // m/s
|
||||
let vmax = 0.1; // m/s
|
||||
let signed_dist = (b.next.p - self.contact_point).dot(&self.normal.into_inner());
|
||||
if signed_dist <= 0.0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let depth = (b.next.p - self.contact_point).magnitude();
|
||||
let depth = (b.next.p - self.contact_point).magnitude() * 0.9;
|
||||
let depth = depth.min(vmax * step.dt);
|
||||
let correction = self.normal.into_inner() * depth;
|
||||
b.next.p += correction;
|
||||
}
|
||||
|
||||
fn priority(&self) -> isize {
|
||||
-100
|
||||
100
|
||||
}
|
||||
|
||||
fn body_idxs(&self) -> Vec<usize> {
|
||||
|
||||
Reference in New Issue
Block a user