This commit is contained in:
Franklin Blanco 2023-11-09 13:00:01 -08:00
parent 1193797a1e
commit 901c30154b
5 changed files with 77 additions and 20 deletions

View File

@ -0,0 +1,10 @@
use bevy::{prelude::Component, reflect::Reflect};
use crate::logic::core::guns::caliber::Caliber;
#[derive(Component, Reflect)]
pub struct BulletMarker {
pub caliber: Caliber
}

View File

@ -2,4 +2,5 @@ pub mod camera;
pub mod firearm;
pub mod holdable;
pub mod player;
pub mod muzzle_flash;
pub mod muzzle_flash;
pub mod bullet;

View File

@ -1,8 +1,9 @@
use std::time::Duration;
use bevy::{prelude::*, render::render_resource::PrimitiveTopology};
use bevy_rapier3d::prelude::*;
use crate::comps::core::markers::muzzle_flash::MuzzleFlashMarker;
use crate::comps::core::markers::{muzzle_flash::MuzzleFlashMarker, bullet::BulletMarker};
use super::caliber::Caliber;
@ -12,7 +13,7 @@ pub fn shoot_bullet(
materials: &mut ResMut<Assets<StandardMaterial>>,
firing_point: Transform,
forward: Vec3,
_up: Vec3,
up: Vec3,
caliber: Caliber
) {
// Spawn muzzle flash LIGHT
@ -47,12 +48,52 @@ pub fn shoot_bullet(
..Default::default()
}
);
spawn_bullet(commands, meshes, materials, firing_point, forward, up, caliber);
}
/*
meshes.add(box_2_mesh.into()),
material: materials.add(StandardMaterial {
base_color: Color::RED,
perceptual_roughness: 1.0,
..default()
}), */
pub fn spawn_bullet(
commands: &mut Commands,
meshes: &mut ResMut<Assets<Mesh>>,
materials: &mut ResMut<Assets<StandardMaterial>>,
firing_point: Transform,
forward: Vec3,
up: Vec3,
caliber: Caliber
) {
commands.spawn(
(
Name::new("Bullet"),
BulletMarker {
caliber
},
MaterialMeshBundle {
mesh: {
meshes.add(
shape::UVSphere { radius: 0.2, sectors: 36, stacks: 18 }.into()
)
},
material: materials.add(StandardMaterial {
base_color: Color::GREEN,
..Default::default()
}),
visibility: Visibility::Visible,
transform: firing_point,
..Default::default()
},
RigidBody::Dynamic,
GravityScale(1.0),
Collider::ball(0.2),
Velocity::zero(),
Damping {
linear_damping: 1.0,
angular_damping: 1.0,
},
ColliderMassProperties::Mass(0.001),
ExternalImpulse {
impulse: forward * 0.1 ,
torque_impulse: Vec3::ZERO,
},
)
);
}

View File

@ -1,5 +1,5 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy_editor_pls::controls::{self, EditorControls};
use bevy_editor_pls::{controls::{self, EditorControls}, default_windows::cameras::EditorCamera};
use bevy_inspector_egui::{egui, bevy_egui::EguiContext, bevy_inspector};
#[allow(unused)]
@ -21,7 +21,6 @@ pub fn inspector_ui(world: &mut World) {
pub fn editor_controls() -> EditorControls {
let mut editor_controls = EditorControls::default_bindings();
editor_controls.unbind(controls::Action::PlayPauseEditor);
editor_controls.insert(
controls::Action::PlayPauseEditor,
@ -30,17 +29,23 @@ pub fn editor_controls() -> EditorControls {
conditions: vec![controls::BindingCondition::ListeningForText(false)],
},
);
editor_controls
}
pub fn set_cam3d_controls(
mut query: Query<&mut bevy_editor_pls::default_windows::cameras::camera_3d_free::FlycamControls>,
mut query_camera_transforms: Query<&mut Transform, With<EditorCamera>>,
) {
let mut controls = query.single_mut();
controls.key_forward = KeyCode::Up;
controls.key_back = KeyCode::Down;
controls.key_left = KeyCode::Left;
controls.key_right = KeyCode::Right;
controls.key_up = KeyCode::U;
for mut controls in query.iter_mut() {
controls.key_forward = KeyCode::Up;
controls.key_back = KeyCode::Down;
controls.key_left = KeyCode::Left;
controls.key_right = KeyCode::Right;
controls.key_up = KeyCode::U;
}
// TODO: run this after the position update already in the editor plugin
for mut transform in query_camera_transforms.iter_mut() {
transform.translation = Vec3 { x: 6.5, y: 28.0, z: 41.6 };
transform.look_at(Vec3::ZERO, Vec3::Y);
}
}

View File

@ -41,7 +41,7 @@ impl Plugin for MainEditorUiPlugin {
.add_plugins(EguiPlugin)
.add_plugins(EditorPlugin::default())
.insert_resource(editor_controls())
.add_systems(Startup, set_cam3d_controls);
.add_systems(PostStartup, set_cam3d_controls);
//.add_plugins(ResourceInspectorPlugin::<MouseMovementSettings>::default());
//.add_plugins(bevy_inspector_egui::DefaultInspectorConfigPlugin) // adds default options and `InspectorEguiImpl`s
//.add_systems(Update, inspector_ui);