Could not find out how to fix bug where stopped collider would not work as precisely as started collision event
This commit is contained in:
parent
4e8bddfade
commit
8c7450d03f
|
@ -2839,6 +2839,17 @@ dependencies = [
|
|||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-derive"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.45"
|
||||
|
@ -2995,7 +3006,7 @@ dependencies = [
|
|||
"jni 0.20.0",
|
||||
"ndk",
|
||||
"ndk-context",
|
||||
"num-derive",
|
||||
"num-derive 0.3.3",
|
||||
"num-traits",
|
||||
"oboe-sys",
|
||||
]
|
||||
|
@ -3106,7 +3117,7 @@ dependencies = [
|
|||
"downcast-rs",
|
||||
"either",
|
||||
"nalgebra",
|
||||
"num-derive",
|
||||
"num-derive 0.3.3",
|
||||
"num-traits",
|
||||
"rustc-hash",
|
||||
"simba",
|
||||
|
@ -3312,8 +3323,6 @@ checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab"
|
|||
[[package]]
|
||||
name = "rapier3d"
|
||||
version = "0.17.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62a8a0bd9d3135f7b4eb45d0796540e7bab47b6b7c974f90567ccc5a0454f42b"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"arrayvec",
|
||||
|
@ -3322,7 +3331,7 @@ dependencies = [
|
|||
"crossbeam",
|
||||
"downcast-rs",
|
||||
"nalgebra",
|
||||
"num-derive",
|
||||
"num-derive 0.4.1",
|
||||
"num-traits",
|
||||
"parry3d",
|
||||
"rustc-hash",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_rapier3d::prelude::*;
|
||||
use bevy_rapier3d::{prelude::*, rapier::prelude::IntegrationParameters};
|
||||
use crate::comps::core::markers::{muzzle_flash::MuzzleFlashMarker, bullet::BulletMarker};
|
||||
|
||||
pub fn despawn_muzzle_flashes(mut commands: Commands, mut query: Query<(&mut MuzzleFlashMarker, Entity)>, time: Res<Time>) {
|
||||
|
@ -17,6 +17,7 @@ pub fn despawn_stray_bullets(
|
|||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
mut query: Query<(&mut BulletMarker, Entity, &Transform)>,
|
||||
mut collisions: EventReader<CollisionEvent>,
|
||||
//res: Res<IntegrationParameters>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let collisions_read: Vec<&CollisionEvent> = collisions.read().collect();
|
||||
|
@ -25,35 +26,24 @@ pub fn despawn_stray_bullets(
|
|||
for event in collisions_read.iter() {
|
||||
match event {
|
||||
CollisionEvent::Started(entity_a, entity_b, _) => {
|
||||
println!("AA");
|
||||
if entity_a == entity_b { // Avoid inner collisions
|
||||
continue;
|
||||
}
|
||||
if entity_a == &bullet_entity {
|
||||
if entity_a == &bullet_entity || entity_b == &bullet_entity{
|
||||
commands.entity(bullet_entity).remove::<Collider>();
|
||||
//commands.entity(*entity_b).despawn();
|
||||
//commands.entity(bullet_entity).insert(Sensor);
|
||||
spawn_bullet_hit_marker(&mut commands, transform.translation, &mut meshes, &mut materials);
|
||||
continue;
|
||||
}
|
||||
else if entity_b == &bullet_entity {
|
||||
commands.entity(bullet_entity).remove::<Collider>();
|
||||
//commands.entity(*entity_a).despawn();
|
||||
spawn_bullet_hit_marker(&mut commands, transform.translation, &mut meshes, &mut materials);
|
||||
continue;
|
||||
}
|
||||
},
|
||||
CollisionEvent::Stopped(entity_a, entity_b, _) => {
|
||||
println!("AAB");
|
||||
if entity_a == &bullet_entity {
|
||||
commands.entity(bullet_entity).insert(Collider::ball(bullet.caliber.size()));
|
||||
//commands.entity(*entity_b).despawn();
|
||||
//spawn_bullet_hit_marker(&mut commands, transform.translation, &mut meshes, &mut materials);
|
||||
if entity_a == entity_b { // Avoid inner collisions
|
||||
continue;
|
||||
}
|
||||
else if entity_b == &bullet_entity {
|
||||
if entity_a == &bullet_entity || entity_b == &bullet_entity{
|
||||
commands.entity(bullet_entity).insert(Collider::ball(bullet.caliber.size()));
|
||||
//commands.entity(*entity_a).despawn();
|
||||
//spawn_bullet_hit_marker(&mut commands, transform.translation, &mut meshes, &mut materials);
|
||||
//commands.entity(bullet_entity).remove::<Sensor>();
|
||||
//commands.entity(*entity_b).despawn();
|
||||
spawn_bullet_exit_marker(&mut commands, transform.translation, &mut meshes, &mut materials);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +74,7 @@ fn spawn_bullet_hit_marker(
|
|||
)
|
||||
},
|
||||
material: materials.add(StandardMaterial {
|
||||
base_color: Color::BLUE,
|
||||
base_color: Color::GREEN,
|
||||
//base_color_texture: Some(Color::GREEN),
|
||||
emissive: Color::GREEN,
|
||||
..Default::default()
|
||||
|
@ -97,3 +87,32 @@ fn spawn_bullet_hit_marker(
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
fn spawn_bullet_exit_marker(
|
||||
commands: &mut Commands,
|
||||
at: Vec3,
|
||||
meshes: &mut ResMut<Assets<Mesh>>,
|
||||
materials: &mut ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
commands.spawn(
|
||||
(
|
||||
MaterialMeshBundle {
|
||||
mesh: {
|
||||
meshes.add(
|
||||
shape::UVSphere { radius: 0.05, sectors: 36, stacks: 18 }.into()
|
||||
)
|
||||
},
|
||||
material: materials.add(StandardMaterial {
|
||||
base_color: Color::RED,
|
||||
//base_color_texture: Some(Color::GREEN),
|
||||
emissive: Color::RED,
|
||||
..Default::default()
|
||||
|
||||
}),
|
||||
visibility: Visibility::Visible,
|
||||
transform: Transform::from_translation(at),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue