nphysics icon indicating copy to clipboard operation
nphysics copied to clipboard

Static bodies' positions aren't propagated to collision world

Open tpdickso opened this issue 8 years ago • 0 comments
trafficstars

Changing the position of a static body using set_transformation and related methods has no apparent effect, as its position in the collision world remains unchanged. A simple workaround is to add this method to the World class:

/// Acknowledge changes to a static rigid body's position.
pub fn update_static_body_position(&mut self, b: &RigidBodyHandle<N>) {
    let rb = b.borrow_mut();
    self.cworld.deferred_set_position(&**b as *const RefCell<RigidBody<N>> as usize,
                                      rb.position().clone());
}

However, this may be considered a bit of a hack. On the other hand, I'm not sure what a better solution would be. Adding a branch to set_transformation to check if the body is static (and if so, add it to a list of objects that need to be updated) might be slow for many physics objects. If sensors and rigid bodies are now distinct objects, though, maybe it would be worth it to have type-level distinction between dynamic and static bodies. For now, the hack does just fine.

tpdickso avatar Apr 06 '17 01:04 tpdickso