Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadMassProperties always return a mass of 0 #271

Closed
miyoku157 opened this issue Nov 9, 2022 · 4 comments
Closed

ReadMassProperties always return a mass of 0 #271

miyoku157 opened this issue Nov 9, 2022 · 4 comments

Comments

@miyoku157
Copy link

miyoku157 commented Nov 9, 2022

I've run a simple code spawning entities in batch like this :

fn setup_benchmark_scene
    (mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    let mut vaisseau= Vec::new();
    let mut rng = thread_rng();
    for _ in 0..2000{
        vaisseau.push(
            (
                meshes.add(Mesh::from(shape::Icosphere {
                    radius: 1.0,
                    subdivisions: 2,
                })),
                materials.add(Color::rgb(rng.gen(), rng.gen(), rng.gen()).into()),
                Transform::from_xyz(rng.gen_range(-100.0..100.0), rng.gen_range(-100.0..100.0), rng.gen_range(-100.0..100.0)),
                GlobalTransform::default(),
                Visibility::default(),
                ComputedVisibility::default(),
                 RigidBody::Dynamic,
                 ActiveCollisionTypes::default(),
                 Collider::ball(1.0),
                 AdditionalMassProperties::Mass(rng.gen_range(50.0..200.0)),
                 ExternalForce{
                    force: Vec3::new(0.0, 0.0, 0.0),
                    torque: Vec3::new(0.0, 0.0, 0.0),
                 },
             )
        );
    }
    commands.spawn_batch(vaisseau);
}

And running this system (which is very close to the example here: https://bevyengine.org/examples/ecs/iter-combinations/)

fn interact_bodies(mut query: Query<(&ReadMassProperties, &GlobalTransform, &mut ExternalForce)>,
                    cont: Res<RapierContext>) {
    let mut iter = query.iter_combinations_mut();
    while let Some([(m1, transform1, mut acc1), (m2, transform2, mut acc2)]) =
        iter.fetch_next()
    {
        let delta = transform2.translation() - transform1.translation();
        let distance_sq: f32 = delta.length_squared();
        

        let f = GRAVITY_CONSTANT / distance_sq;
        
        let force_unit_mass = delta * f;
        acc1.force += force_unit_mass * m1.0.mass;
        acc2.force -= force_unit_mass * m2.0.mass;
        
    }
}

But when i do the mass of m1 and m2 are always equals to 0. To retrieve the mass, i currently use a workaround using rapierContext resources and RigidbodyHandle:
cont.bodies[m1.0].mass()

@rdelfin
Copy link

rdelfin commented Feb 6, 2023

I'm experiencing the same issue. @miyoku157 were you able to resolve?

@miyoku157
Copy link
Author

Currently i'm on the last version of the library, but i didn't find any solution except the workaround.

@Aceeri
Copy link
Sponsor Contributor

Aceeri commented Aug 15, 2023

I believe this should be fixed in the next release, previously it wasn't being updated when the changed.

AnthonyTornetta added a commit to AnthonyTornetta/bevy_rapier that referenced this issue Sep 15, 2023
@Vrixyz
Copy link
Contributor

Vrixyz commented May 24, 2024

I believe that's fixed, please open a new issue (and link there) if need be.

@Vrixyz Vrixyz closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants