diff --git a/Design.md b/Design.md index 6fa470e..b48da22 100644 --- a/Design.md +++ b/Design.md @@ -47,7 +47,7 @@ Multiplayer - [ ] Gun Bob on walk - [ ] Reload animation (procedural) - [ ] Real world magazines -- [ ] Rewriting bullet physics to use raycasts & kinematic rigidbodies (logic controlled) +- [x] Rewriting bullet physics to use raycasts & kinematic rigidbodies (logic controlled) - [x] Create a Controls struct that holds mappings to all the game keys and replace them in all the game's code - [x] Gun dropping drops on only one side of player - [x] Gun dropping does not apply impulse for some reason... diff --git a/src/comps/core/markers/bullet.rs b/src/comps/core/markers/bullet.rs index ff99f66..0c27da8 100644 --- a/src/comps/core/markers/bullet.rs +++ b/src/comps/core/markers/bullet.rs @@ -1,11 +1,17 @@ use bevy::{ prelude::{Component, Vec3}, reflect::Reflect, - time::Timer, ecs::reflect::ReflectComponent, + time::Timer, ecs::{reflect::ReflectComponent, entity::Entity}, }; use crate::comps::core::weapons::caliber::Caliber; +#[derive(PartialEq, Clone, Reflect)] +pub struct BulletHit { + pub entity: Entity, + pub position: Vec3, +} + #[derive(Component, Reflect, Default)] #[reflect(Component)] pub struct BulletMarker { @@ -13,4 +19,5 @@ pub struct BulletMarker { pub starting_point: Vec3, pub timer: Timer, pub current_velocity: Vec3, + pub hits: Vec, } diff --git a/src/logic/core/guns/despawn_shots.rs b/src/logic/core/guns/despawn_shots.rs index 48cf5b8..c28474a 100644 --- a/src/logic/core/guns/despawn_shots.rs +++ b/src/logic/core/guns/despawn_shots.rs @@ -68,7 +68,7 @@ pub fn despawn_stray_bullets( } } -fn spawn_bullet_hit_marker( +pub fn spawn_bullet_hit_marker( commands: &mut Commands, at: Vec3, meshes: &mut ResMut>, diff --git a/src/logic/core/guns/shoot.rs b/src/logic/core/guns/shoot.rs index fb3ef72..29aa26d 100644 --- a/src/logic/core/guns/shoot.rs +++ b/src/logic/core/guns/shoot.rs @@ -1,9 +1,9 @@ use std::time::Duration; -use bevy::{prelude::*, render::render_resource::PrimitiveTopology}; +use bevy::prelude::*; use bevy_rapier3d::prelude::*; -use crate::{comps::core::{markers::{bullet::BulletMarker, muzzle_flash::MuzzleFlashMarker, collider_flags::ColliderFlags}, 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}; pub fn shoot_bullet( @@ -14,7 +14,6 @@ pub fn shoot_bullet( forward: Vec3, up: Vec3, caliber: Caliber, - player_settings: &Res ) { // Spawn muzzle flash LIGHT commands.spawn(( @@ -40,7 +39,7 @@ pub fn shoot_bullet( )); // Spawn Line - if player_settings.shot_lines_enabled { + /*if player_settings.shot_lines_enabled { commands.spawn( MaterialMeshBundle { mesh: { @@ -57,13 +56,15 @@ pub fn shoot_bullet( ..Default::default() } ); - } + }*/ spawn_bullet( commands, meshes, materials, firing_point, + up, + forward, caliber, ); } @@ -73,6 +74,8 @@ pub fn spawn_bullet( meshes: &mut ResMut>, materials: &mut ResMut>, firing_point: Transform, + _up: Vec3, + forward: Vec3, caliber: Caliber, ) { commands.spawn(( @@ -84,7 +87,8 @@ pub fn spawn_bullet( Duration::from_secs_f32(caliber.max_airtime_secs()), TimerMode::Once, ), - current_velocity: firing_point.forward() * caliber.muzzle_velocity(), + current_velocity: forward * caliber.muzzle_velocity(), + hits: Vec::new() }, MaterialMeshBundle { mesh: { diff --git a/src/logic/core/guns/update_bullet.rs b/src/logic/core/guns/update_bullet.rs index 1533040..a7b30ce 100644 --- a/src/logic/core/guns/update_bullet.rs +++ b/src/logic/core/guns/update_bullet.rs @@ -1,17 +1,83 @@ -use bevy::prelude::*; +use bevy::{prelude::*, render::render_resource::PrimitiveTopology, ecs::system::SystemParam}; use bevy_rapier3d::prelude::*; -use crate::comps::core::markers::bullet::BulletMarker; +use crate::{comps::core::{markers::{bullet::{BulletMarker, BulletHit}, proxy::weapons::gun_colliders::GunFirearmCollider}, events::{bullet_collision::BulletCollisionEvent, collision_event_type::CollisionEventType}}, logic::core::player::player_settings::PlayerSettings}; + +#[derive(SystemParam)] +pub struct UpdateBulletQueryParams<'w, 's> { + bullets: Query<'w, 's, (Entity, &'static mut BulletMarker, &'static mut Transform)>, + firearm_colliders: Query<'w, 's, Entity, With>, +} pub fn update_bullet( mut commands: Commands, - mut bullets: Query<(Entity, &mut BulletMarker, &mut Transform)>, time: Res