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

read the force applied by the joint in order to break it dynamically #591

Closed
johnny-smitherson opened this issue Oct 9, 2024 · 1 comment

Comments

@johnny-smitherson
Copy link

The attempt is to break fixed joints when some limit in force/impulse is reached. The joints are added using the child entity method from the joint3 / despawn joint example.

In the docs on joints, under the FixedJoints section, there is this note

https://rapier.rs/docs/user_guides/bevy_plugin/joints

... (for example if you want to read the force applied by the joint in order to break it dynamically).

But I can't find any examples on this subject, or the subject of reading forces applied to entities by the joints.


Is there some kind of event similar to these that can be queried to obtain some info on the joints?

I don't suppose the joint impulses/forces will show up either as "contact forces" or "collisions"


In rapier3d ImpulseJoint there is a field impulses with comment The impulses applied by this joint. How would I read this value from a bevy system? The bevy ImpulseJoint holds a TypeJoint that holds a FixedJoint that holds a GenericJoint that holds a rapier3d GenericJoint that doesn't have the impulse information.

In rapier3d JointLimits there is a field for max impulse; this seems to be not used in the bevy_rapier3d joint limits. It's also not obvious how one would use reaching this limit to break the joint, without being able to read the impulse; maybe by double checking the relative positions and manually checking if the joint was overstretched?

Thanks,

@johnny-smitherson
Copy link
Author

found on discord


fn unstick(
    mut commands: Commands,
    mut context: ResMut<RapierContext>,
    mut joints: Query<(Entity, &RapierImpulseJointHandle)>,
) {
    for (joint_entity, rapier_joint_handle) in joints.iter_mut() {
        if let Some(rapier_joint) = context.impulse_joints.get_mut(rapier_joint_handle.0) {
            for impulse in rapier_joint.impulses.column_iter() {
                let impulse_magnitude: f32 = Vec2::new(impulse.x, impulse.y).length();
                if impulse_magnitude > 0.000005 {
                    commands.entity(joint_entity).despawn();
                }
            }
        }
    }
}


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

1 participant