Added collision groups. AND Gun colliding with bullet, making it lower on every shot fired.

- [x] Optics
This commit is contained in:
Franklin 2023-11-25 18:04:35 -04:00
parent c1cd45192d
commit 235ca21895
9 changed files with 48 additions and 24 deletions

35
Cargo.lock generated
View File

@ -555,7 +555,7 @@ dependencies = [
"bevy_render",
"bevy_transform",
"bevy_utils",
"bitflags 2.4.0",
"bitflags 2.4.1",
"radsort",
"serde",
]
@ -768,7 +768,7 @@ checksum = "dca4b0a04e401d05dc74bc829f2e41bd62afdbacc095165fadb4e93caf0ba546"
dependencies = [
"anyhow",
"bevy",
"bitflags 2.4.0",
"bitflags 2.4.1",
"bytemuck",
"copyless",
"rand",
@ -927,7 +927,7 @@ dependencies = [
"bevy_transform",
"bevy_utils",
"bevy_window",
"bitflags 2.4.0",
"bitflags 2.4.1",
"bytemuck",
"fixedbitset",
"naga_oil",
@ -949,7 +949,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3f0a2641af76c9eb17da0dcb0fb20cd9d615b93b67be0b85f1867487e956b5a"
dependencies = [
"bevy",
"bitflags 2.4.0",
"bitflags 2.4.1",
"log",
"nalgebra",
"rapier3d",
@ -1011,7 +1011,7 @@ dependencies = [
"bevy_transform",
"bevy_utils",
"bevy_window",
"bitflags 2.4.0",
"bitflags 2.4.1",
"bytemuck",
"codespan-reporting",
"downcast-rs",
@ -1083,7 +1083,7 @@ dependencies = [
"bevy_render",
"bevy_transform",
"bevy_utils",
"bitflags 2.4.0",
"bitflags 2.4.1",
"bytemuck",
"fixedbitset",
"guillotiere",
@ -1299,9 +1299,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.0"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
dependencies = [
"serde",
]
@ -1725,7 +1725,7 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e16e44ab292b1dddfdaf7be62cfd8877df52f2f3fde5858d95bab606be259f20"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"libloading 0.8.0",
"winapi",
]
@ -1918,6 +1918,7 @@ dependencies = [
"bevy_gltf_components",
"bevy_hanabi",
"bevy_rapier3d",
"bitflags 2.4.1",
"uuid",
]
@ -2187,7 +2188,7 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbcd2dba93594b227a1f57ee09b8b9da8892c34d55aa332e034a228d0fe6a171"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"gpu-alloc-types",
]
@ -2197,7 +2198,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98ff03b468aa837d70984d55f5d3f846f6ec31fe34bbb97c4f85219caeee1ca4"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
]
[[package]]
@ -2642,7 +2643,7 @@ version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "623b5e6cefd76e58f774bd3cc0c6f5c7615c58c03a97815245a25c3c9bdee318"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"block",
"core-graphics-types",
"foreign-types 0.5.0",
@ -2686,7 +2687,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ceaaa4eedaece7e4ec08c55c640ba03dbb73fb812a6570a59bcf1930d0f70e"
dependencies = [
"bit-set",
"bitflags 2.4.0",
"bitflags 2.4.1",
"codespan-reporting",
"hexf-parse",
"indexmap 1.9.3",
@ -3466,7 +3467,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
dependencies = [
"base64 0.21.4",
"bitflags 2.4.0",
"bitflags 2.4.1",
"serde",
"serde_derive",
]
@ -4182,7 +4183,7 @@ checksum = "0f8a44dd301a30ceeed3c27d8c0090433d3da04d7b2a4042738095a424d12ae7"
dependencies = [
"arrayvec",
"bit-vec",
"bitflags 2.4.0",
"bitflags 2.4.1",
"codespan-reporting",
"log",
"naga",
@ -4207,7 +4208,7 @@ dependencies = [
"arrayvec",
"ash",
"bit-set",
"bitflags 2.4.0",
"bitflags 2.4.1",
"block",
"core-graphics-types",
"d3d12",
@ -4244,7 +4245,7 @@ version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee64d7398d0c2f9ca48922c902ef69c42d000c759f3db41e355f4a570b052b67"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"js-sys",
"web-sys",
]

View File

@ -23,6 +23,7 @@ bevy_hanabi = { version = "0.8", default-features = false, features = [ "3d" ] }
bevy-trait-query = "0.4.0"
bevy_gltf_components = "0.2.0"
bitflags = "2.4.1"
uuid = { version = "1.6.1", features = [
"v4", # Lets you generate random UUIDs

View File

@ -34,9 +34,11 @@ Multiplayer
- [x] EventCollision system that takes into account more than one type of collider.
- [x] Auto Low ready when gun collider hits object OR when player starts sprinting
- [ ] (Not a priority) Collision with wall and attempting to Aim can look very twitchy, maybe add a cooldown of 0.1-0.4s on each change from low ready to high ready
- [x] Gun colliding with bullet, making it lower on every shot fired.
- [x] Optics
- [x] All optics implementing a fn/trait that gives a specific gun offset to use the optic correctly
- [ ] TODO: Find some way to implement a shader for the optics
- [ ] Weapon Clipping ()
- [ ] Bobbing
- [ ] Gun Bob on run
- [ ] Gun Bob on walk

View File

@ -0,0 +1,17 @@
use bitflags::bitflags;
#[derive(Default, Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct ColliderFlags(u32);
bitflags! {
impl ColliderFlags: u32 {
/// The value `A`, at bit position `0`.
const BULLETS = 0b00000001;
/// The value `B`, at bit position `1`.
const GUNS = 0b00000010;
/// The value `C`, at bit position `2`.
const SOLIDS = 0b00000100;
const ALL = u32::MAX;
const NONE = 0;
}
}

View File

@ -7,4 +7,5 @@ pub mod muzzle_flash;
pub mod player;
pub mod settings_screen;
pub mod proxy;
pub mod inspect_screen;
pub mod inspect_screen;
pub mod collider_flags;

View File

@ -1,7 +1,7 @@
use bevy::prelude::*;
use bevy_rapier3d::geometry::{Sensor, ActiveEvents};
use bevy_rapier3d::geometry::{Sensor, ActiveEvents, Group, CollisionGroups};
use crate::{comps::core::markers::holdable::InPlayerHands, utils::hierarchy::find_child_in_parent_children};
use crate::{comps::core::markers::{holdable::InPlayerHands, collider_flags::ColliderFlags}, utils::hierarchy::find_child_in_parent_children};
/// This marker is to find the gun's collider that should be a sensor when equipped and a non-sensor when on the ground
@ -19,7 +19,7 @@ pub fn update_gun_collider(
let mut found = false;
for in_player_hands_entity in in_player_hands_query.iter() {
if find_child_in_parent_children(&mut commands, in_player_hands_entity, gun_firearm_collider_entity, &children) {
commands.entity(gun_firearm_collider_entity).insert(Sensor).insert(ActiveEvents::COLLISION_EVENTS);
commands.entity(gun_firearm_collider_entity).insert(Sensor).insert(ActiveEvents::COLLISION_EVENTS).insert(CollisionGroups::new(Group::from_bits_retain(ColliderFlags::GUNS.bits()), Group::from_bits_retain(ColliderFlags::SOLIDS.bits())),);
found = true;
}
}

View File

@ -41,12 +41,11 @@ pub fn collision_handler(
if entity_a == entity_b { continue; } // Avoid inner collisions
if flags.contains(CollisionEventFlags::SENSOR) { // Sensor collision event handling
println!("Sensor collision");
// ######
// Equipped Firearm Collisions
// ######
for gun_collider in queries.firearms.iter() {
println!("Gun collider entity detected");
if &gun_collider == entity_a {
events.equipped_gun_collision_events.send(EquippedGunCollisionEvent {
gun: gun_collider,

View File

@ -41,6 +41,7 @@ pub fn despawn_stray_bullets(
CollisionEventType::End => {
for (bullet, bullet_entity, _) in query.iter() {
if bullet_entity != event.bullet { continue; }
println!("Happened");
commands
.entity(event.bullet)
.insert(Collider::ball(bullet.caliber.size()));

View File

@ -3,7 +3,7 @@ use std::time::Duration;
use bevy::{prelude::*, render::render_resource::PrimitiveTopology};
use bevy_rapier3d::prelude::*;
use crate::{comps::core::{markers::{bullet::BulletMarker, muzzle_flash::MuzzleFlashMarker}, weapons::caliber::Caliber}, logic::core::player::player_settings::PlayerSettings};
use crate::{comps::core::{markers::{bullet::BulletMarker, muzzle_flash::MuzzleFlashMarker, collider_flags::ColliderFlags}, weapons::caliber::Caliber}, logic::core::player::player_settings::PlayerSettings};
pub fn shoot_bullet(
@ -127,6 +127,8 @@ pub fn spawn_bullet(
torque_impulse: Vec3::ZERO,
},
ActiveEvents::COLLISION_EVENTS,
CollisionGroups::new(Group::from_bits_retain(ColliderFlags::BULLETS.bits()), Group::from_bits_retain(ColliderFlags::SOLIDS.bits())),
Ccd::enabled(),
));
}