#Reparenting a child rapier collider

8 messages · Page 1 of 1 (latest)

fallen verge
#

Does any know how to reparent a rapier collider without things getting funky?
It’s for one of the mechanic in my game where players suppose to be able to connect rigid things together (fixed joints in rapier is not fixed enough). But after the reparent process, the merged rigid body just kept breaking the law of physics. I suspect that there’s a cache in RapierColliderHandle some where that’s not updating the parent rigid body but i’m not sure how to solve it currently.

fallen verge
#

Found out that init_colliders and sync_removals doesn't check for reparenting. Now seems like I need do manual reparenting with rapier

#

them code digging time

#

there's too much stuff to do this manually :<

#

i think can do some tinkering for workaround stuff.

#

decided to go with making a new patch system to receive events called ColliderReset which will then trigger both of the mentioned system in order.

fallen verge
#

trying this one:

pub fn rapier_patch_plugin(app: &mut App) {
    app.add_systems(PostUpdate, collider_reset.in_set(PhysicsSet::SyncBackend));
}

#[derive(Event, Clone, Copy)]
pub struct ColliderReset {
    pub target: Entity,
}

pub fn collider_reset(world: &mut World) {
    let reset_res = world.resource::<Events<ColliderReset>>();
    let mut reset_reader = reset_res.get_reader_current();
    let reset = reset_reader.read(&*reset_res).copied().collect::<Vec<_>>();
    let mut target_store = vec![];
    reset.into_iter().for_each(|ColliderReset { target }| {
        let mut entity = world.entity_mut(target);
        let components = entity.take::<Collider>().unwrap();
        target_store.push((target, components));
    });
    world.run_system_once(sync_removals);
    target_store.into_iter().for_each(|(entity, components)| {
        let mut entity = world.entity_mut(entity);
        entity.insert(components);
    });
    world.run_system_once(init_colliders);
}
#

hmm