Not getting CollisionEvent
's from bevy_rapier2d
#6805
-
Sorry if this isn't the right place to ask a question about Hello, I am trying to detect collision events with how im spawning the marble: commands
.spawn_atlas_sprite( // my own thing
basic::marble_small,
Color::GREEN,
Transform::from_translation(pos - pos.z), // z-position: 0
)
.insert((
Collider::ball(basic::marble_small.width() * 0.5),
RigidBody::Dynamic,
Velocity {
linvel: transform.rotation.mul_vec3(Vec3::X).truncate() * 80.0,
angvel: 0.0,
},
ColliderMassProperties::Mass(1.0),
Restitution::coefficient(0.9),
))
.insert(event.marble)
.insert(Name::new("bit.marble")); and how im spawning the input / output colliders: let rotation = Quat::from_rotation_z(rotation);
let translation = rotation.mul_vec3(Vec3::X * offset) + Vec3::Z * z;
let transform = Transform {
rotation,
translation,
scale: Vec3::ONE,
}
cmd.spawn((
SpriteSheetBundle {
texture_atlas,
transform
sprite: TextureAtlasSprite {
index,
color: Color::GRAY,
anchor: Anchor::Center,
..default()
},
..default()
},
Collider::ball(basic::marble_output.width() * 0.5),
Sensor,
marker::Output,
Name::new("out.component"),
)) and the system for detecting the collision events (which definitely runs i didn't forget to put it in the schedule) (also this is just copied from the rapier docs): fn display_events(
mut collision_events: EventReader<CollisionEvent>,
mut contact_force_events: EventReader<ContactForceEvent>,
) {
for collision_event in collision_events.iter() {
println!("Received collision event: {:?}", collision_event);
}
for contact_force_event in contact_force_events.iter() {
println!("Received contact force event: {:?}", contact_force_event);
}
} ive tried setting their z-positions to be the same which i didn't think would matter (it didnt) i know the obvious solution to detect collisions like this would be to have a system that checks each marble to see if its intersecting with each sensor but i hope theres a better solution. thanks in advance 🙂 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The "flag" language is slightly confusing there, but you need to insert the |
Beta Was this translation helpful? Give feedback.
From https://rapier.rs/docs/user_guides/bevy_plugin/advanced_collision_detection#collision-and-contact-force-events
The "flag" language is slightly confusing there, but you need to insert the
ActiveEvents::COLLISION_EVENTS
component onto the entities.