update project
This commit is contained in:
39
Cargo.lock
generated
39
Cargo.lock
generated
@@ -3306,11 +3306,12 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "erased-serde"
|
name = "erased-serde"
|
||||||
version = "0.4.6"
|
version = "0.4.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e004d887f51fcb9fef17317a2f3525c887d8aa3f4f50fed920816a688284a5b7"
|
checksum = "89e8918065695684b2b0702da20382d5ae6065cf3327bc2d6436bd49a71ce9f3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_core",
|
||||||
"typeid",
|
"typeid",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4025,9 +4026,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "inventory"
|
name = "inventory"
|
||||||
version = "0.3.20"
|
version = "0.3.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ab08d7cd2c5897f2c949e5383ea7c7db03fb19130ffcfbf7eda795137ae3cb83"
|
checksum = "009ae045c87e7082cb72dab0ccd01ae075dd00141ddc108f43a0ea150a9e7227"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustversion",
|
"rustversion",
|
||||||
]
|
]
|
||||||
@@ -4645,7 +4646,7 @@ version = "0.50.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.60.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5329,9 +5330,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.95"
|
version = "1.0.106"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
@@ -5366,9 +5367,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.40"
|
version = "1.0.44"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
@@ -5662,9 +5663,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.21"
|
version = "1.0.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ruzstd"
|
name = "ruzstd"
|
||||||
@@ -5977,9 +5978,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.114"
|
version = "2.0.117"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -6290,9 +6291,9 @@ checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typetag"
|
name = "typetag"
|
||||||
version = "0.2.20"
|
version = "0.2.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73f22b40dd7bfe8c14230cf9702081366421890435b2d625fa92b4acc4c3de6f"
|
checksum = "be2212c8a9b9bcfca32024de14998494cf9a5dfa59ea1b829de98bac374b86bf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"erased-serde",
|
"erased-serde",
|
||||||
"inventory",
|
"inventory",
|
||||||
@@ -6303,9 +6304,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typetag-impl"
|
name = "typetag-impl"
|
||||||
version = "0.2.20"
|
version = "0.2.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "35f5380909ffc31b4de4f4bdf96b877175a016aa2ca98cee39fcfd8c4d53d952"
|
checksum = "27a7a9b72ba121f6f1f6c3632b85604cac41aedb5ddc70accbebb6cac83de846"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -6320,9 +6321,9 @@ checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.18"
|
version = "1.0.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-linebreak"
|
name = "unicode-linebreak"
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = "0.18.0"
|
bevy = "0.18.0"
|
||||||
serde = "1.0.219"
|
serde = "1.0.228"
|
||||||
typetag = "0.2.20"
|
typetag = "0.2.21"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ron = "0.10.1"
|
ron = "0.10.1"
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ use plugins::GamePlugin;
|
|||||||
mod components;
|
mod components;
|
||||||
mod resources;
|
mod resources;
|
||||||
const NAME: &str = "Space Game";
|
const NAME: &str = "Space Game";
|
||||||
fn main() {
|
fn main()
|
||||||
|
{
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
DefaultPlugins
|
DefaultPlugins
|
||||||
@@ -17,7 +18,7 @@ fn main() {
|
|||||||
title: NAME.into(),
|
title: NAME.into(),
|
||||||
name: Some(NAME.into()),
|
name: Some(NAME.into()),
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
resolution: (1920., 1080.).into(),
|
resolution: (1920, 1080).into(),
|
||||||
present_mode: PresentMode::AutoNoVsync,
|
present_mode: PresentMode::AutoNoVsync,
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
mode: bevy::window::WindowMode::BorderlessFullscreen,
|
mode: bevy::window::WindowMode::BorderlessFullscreen,
|
||||||
@@ -30,9 +31,7 @@ fn main() {
|
|||||||
watch_for_changes_override: Some(true),
|
watch_for_changes_override: Some(true),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
EguiPlugin {
|
EguiPlugin::default(),
|
||||||
enable_multipass_for_primary_context: true,
|
|
||||||
},
|
|
||||||
WorldInspectorPlugin::new(),
|
WorldInspectorPlugin::new(),
|
||||||
GamePlugin,
|
GamePlugin,
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ use crate::{components::camera::*, states::play::PlaySystems};
|
|||||||
|
|
||||||
pub struct CameraPlugin;
|
pub struct CameraPlugin;
|
||||||
|
|
||||||
impl Plugin for CameraPlugin {
|
impl Plugin for CameraPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.add_systems(Update, camera_pitch.in_set(PlaySystems));
|
app.add_systems(Update, camera_pitch.in_set(PlaySystems));
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
PostUpdate,
|
PostUpdate,
|
||||||
@@ -23,12 +25,16 @@ impl Plugin for CameraPlugin {
|
|||||||
pub fn camera_attachment(
|
pub fn camera_attachment(
|
||||||
attachment_targets: Query<&GlobalTransform>,
|
attachment_targets: Query<&GlobalTransform>,
|
||||||
cam: Single<(&mut Transform, &CameraAttachment, &CameraMode)>,
|
cam: Single<(&mut Transform, &CameraAttachment, &CameraMode)>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let (mut transform, attach, mode) = cam.into_inner();
|
let (mut transform, attach, mode) = cam.into_inner();
|
||||||
|
|
||||||
if let Ok(tgt) = attachment_targets.get(attach.0) {
|
if let Ok(tgt) = attachment_targets.get(attach.0)
|
||||||
match mode {
|
{
|
||||||
CameraMode::Player => {
|
match mode
|
||||||
|
{
|
||||||
|
CameraMode::Player =>
|
||||||
|
{
|
||||||
transform.rotation = tgt.rotation();
|
transform.rotation = tgt.rotation();
|
||||||
transform.translation = tgt.translation();
|
transform.translation = tgt.translation();
|
||||||
}
|
}
|
||||||
@@ -38,8 +44,10 @@ pub fn camera_attachment(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn camera_pitch(cam_query: Query<(&mut Transform, &CameraPitch)>) {
|
pub fn camera_pitch(cam_query: Query<(&mut Transform, &CameraPitch)>)
|
||||||
for (mut cam_transform, pitch) in cam_query {
|
{
|
||||||
|
for (mut cam_transform, pitch) in cam_query
|
||||||
|
{
|
||||||
cam_transform.rotation = Quat::from_rotation_x(pitch.0);
|
cam_transform.rotation = Quat::from_rotation_x(pitch.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,20 +55,25 @@ pub fn camera_pitch(cam_query: Query<(&mut Transform, &CameraPitch)>) {
|
|||||||
#[cfg(feature = "dev")]
|
#[cfg(feature = "dev")]
|
||||||
pub fn camera_toggle(
|
pub fn camera_toggle(
|
||||||
key: Res<ButtonInput<KeyCode>>,
|
key: Res<ButtonInput<KeyCode>>,
|
||||||
mut window: Single<&mut Window, With<PrimaryWindow>>,
|
mut cursor_options: Single<&mut CursorOptions, With<PrimaryWindow>>,
|
||||||
camera: Single<&mut CameraMode>,
|
camera: Single<&mut CameraMode>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
use bevy::window::CursorGrabMode;
|
use bevy::window::CursorGrabMode;
|
||||||
let mut mode = camera.into_inner();
|
let mut mode = camera.into_inner();
|
||||||
if key.just_pressed(KeyCode::Escape) {
|
if key.just_pressed(KeyCode::Escape)
|
||||||
if window.cursor_options.visible {
|
{
|
||||||
|
if cursor_options.visible
|
||||||
|
{
|
||||||
*mode = CameraMode::Player;
|
*mode = CameraMode::Player;
|
||||||
window.cursor_options.grab_mode = CursorGrabMode::Locked;
|
cursor_options.grab_mode = CursorGrabMode::Locked;
|
||||||
window.cursor_options.visible = false;
|
cursor_options.visible = false;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
*mode = CameraMode::Disabled;
|
*mode = CameraMode::Disabled;
|
||||||
window.cursor_options.grab_mode = CursorGrabMode::None;
|
cursor_options.grab_mode = CursorGrabMode::None;
|
||||||
window.cursor_options.visible = true;
|
cursor_options.visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ use bevy_rapier3d::prelude::*;
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct GamePlugin;
|
pub struct GamePlugin;
|
||||||
|
|
||||||
impl Plugin for GamePlugin {
|
impl Plugin for GamePlugin
|
||||||
fn build(&self, app: &mut bevy::app::App) {
|
{
|
||||||
|
fn build(&self, app: &mut bevy::app::App)
|
||||||
|
{
|
||||||
app.add_plugins((
|
app.add_plugins((
|
||||||
FollowCamPlugin,
|
FollowCamPlugin,
|
||||||
CameraPlugin,
|
CameraPlugin,
|
||||||
@@ -40,8 +42,9 @@ fn setup_scene(
|
|||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
mut window: Single<&mut Window, With<PrimaryWindow>>,
|
mut window: Single<&mut CursorOptions, With<PrimaryWindow>>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
window.cursor_options.visible = false;
|
window.cursor_options.visible = false;
|
||||||
window.cursor_options.grab_mode = CursorGrabMode::Locked;
|
window.cursor_options.grab_mode = CursorGrabMode::Locked;
|
||||||
|
|
||||||
@@ -105,11 +108,8 @@ fn setup_scene(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn spawn_ship(
|
fn spawn_ship(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>)
|
||||||
mut commands: Commands,
|
{
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
||||||
) {
|
|
||||||
let window_material = materials.add(Color::linear_rgba(1.0, 0.0, 1.0, 0.5));
|
let window_material = materials.add(Color::linear_rgba(1.0, 0.0, 1.0, 0.5));
|
||||||
|
|
||||||
let material = materials.add(Color::BLACK);
|
let material = materials.add(Color::BLACK);
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ use crate::{
|
|||||||
|
|
||||||
pub struct PlayerPlugin;
|
pub struct PlayerPlugin;
|
||||||
|
|
||||||
impl Plugin for PlayerPlugin {
|
impl Plugin for PlayerPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.add_systems(PreUpdate, (keyboard_input, player_look).in_set(InputWorldSystems));
|
app.add_systems(PreUpdate, (keyboard_input, player_look).in_set(InputWorldSystems));
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
Update,
|
Update,
|
||||||
@@ -28,7 +30,8 @@ impl Plugin for PlayerPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_forces(player: Single<(&mut PlayerVelocity, &PlayerForce), With<Player>>, time: Res<Time>) {
|
fn apply_forces(player: Single<(&mut PlayerVelocity, &PlayerForce), With<Player>>, time: Res<Time>)
|
||||||
|
{
|
||||||
let (mut vel, force) = player.into_inner();
|
let (mut vel, force) = player.into_inner();
|
||||||
|
|
||||||
vel.0 += force.0 * time.delta_secs();
|
vel.0 += force.0 * time.delta_secs();
|
||||||
@@ -45,23 +48,31 @@ fn apply_gravity(
|
|||||||
With<Player>,
|
With<Player>,
|
||||||
>,
|
>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let (mut vel, dir, scale, output) = player.into_inner();
|
let (mut vel, dir, scale, output) = player.into_inner();
|
||||||
let Some(grav) = dir.0.map(|d| d.as_vec3()) else {
|
let Some(grav) = dir.0.map(|d| d.as_vec3())
|
||||||
|
else
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let is_grounded = output.map(|o| o.grounded).unwrap_or(false);
|
let is_grounded = output.map(|o| o.grounded).unwrap_or(false);
|
||||||
if !is_grounded {
|
if !is_grounded
|
||||||
|
{
|
||||||
vel.0 += grav * scale.0 * 9.47 * time.delta_secs();
|
vel.0 += grav * scale.0 * 9.47 * time.delta_secs();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
let dot = vel.0.dot(grav);
|
let dot = vel.0.dot(grav);
|
||||||
if dot > f32::EPSILON {
|
if dot > f32::EPSILON
|
||||||
|
{
|
||||||
vel.0 -= dot * grav;
|
vel.0 -= dot * grav;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_drag(player: Single<(&mut PlayerVelocity, &PlayerDrag), With<Player>>, time: Res<Time>) {
|
fn apply_drag(player: Single<(&mut PlayerVelocity, &PlayerDrag), With<Player>>, time: Res<Time>)
|
||||||
|
{
|
||||||
let (mut vel, drag) = player.into_inner();
|
let (mut vel, drag) = player.into_inner();
|
||||||
vel.0 *= (1.0 - drag.0 * time.delta_secs()).max(0.0);
|
vel.0 *= (1.0 - drag.0 * time.delta_secs()).max(0.0);
|
||||||
}
|
}
|
||||||
@@ -77,7 +88,8 @@ fn apply_motion(
|
|||||||
With<Player>,
|
With<Player>,
|
||||||
>,
|
>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let (mut controller, transform, vel, motion) = player.into_inner();
|
let (mut controller, transform, vel, motion) = player.into_inner();
|
||||||
// let max_vel = vel.0.clamp_length_max(500.0);
|
// let max_vel = vel.0.clamp_length_max(500.0);
|
||||||
let global_motion = transform.rotation * motion.0;
|
let global_motion = transform.rotation * motion.0;
|
||||||
@@ -97,26 +109,34 @@ fn keyboard_input(
|
|||||||
),
|
),
|
||||||
With<Player>,
|
With<Player>,
|
||||||
>,
|
>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let (mut motion, mut vel, speed, jump, transform, output) = player.into_inner();
|
let (mut motion, mut vel, speed, jump, transform, output) = player.into_inner();
|
||||||
let mut move_vec = Vec3::ZERO;
|
let mut move_vec = Vec3::ZERO;
|
||||||
|
|
||||||
if key.pressed(KeyCode::KeyW) {
|
if key.pressed(KeyCode::KeyW)
|
||||||
|
{
|
||||||
move_vec.z = -1.0;
|
move_vec.z = -1.0;
|
||||||
} else if key.pressed(KeyCode::KeyS) {
|
}
|
||||||
|
else if key.pressed(KeyCode::KeyS)
|
||||||
|
{
|
||||||
move_vec.z = 1.0;
|
move_vec.z = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if key.pressed(KeyCode::KeyA) {
|
if key.pressed(KeyCode::KeyA)
|
||||||
|
{
|
||||||
move_vec.x = -1.0;
|
move_vec.x = -1.0;
|
||||||
} else if key.pressed(KeyCode::KeyD) {
|
}
|
||||||
|
else if key.pressed(KeyCode::KeyD)
|
||||||
|
{
|
||||||
move_vec.x = 1.0;
|
move_vec.x = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
move_vec = move_vec.normalize_or_zero() * speed.0;
|
move_vec = move_vec.normalize_or_zero() * speed.0;
|
||||||
|
|
||||||
let is_grounded = output.map(|o| o.grounded).unwrap_or(false);
|
let is_grounded = output.map(|o| o.grounded).unwrap_or(false);
|
||||||
if key.just_pressed(KeyCode::Space) && is_grounded {
|
if key.just_pressed(KeyCode::Space) && is_grounded
|
||||||
|
{
|
||||||
vel.0 += transform.up() * jump.0;
|
vel.0 += transform.up() * jump.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,9 +151,10 @@ fn keyboard_input(
|
|||||||
fn player_look(
|
fn player_look(
|
||||||
mut player: Single<&mut Transform, With<Player>>,
|
mut player: Single<&mut Transform, With<Player>>,
|
||||||
mut cam_pitch: Single<&mut CameraPitch>,
|
mut cam_pitch: Single<&mut CameraPitch>,
|
||||||
mouse_motion: EventReader<MouseMotion>,
|
mouse_motion: MessageReader<MouseMotion>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let delta = get_mouse_delta(mouse_motion) * -time.delta_secs();
|
let delta = get_mouse_delta(mouse_motion) * -time.delta_secs();
|
||||||
let up = player.up();
|
let up = player.up();
|
||||||
player.rotate_axis(up, delta.x);
|
player.rotate_axis(up, delta.x);
|
||||||
@@ -150,15 +171,19 @@ fn align_with_gravity(
|
|||||||
With<Player>,
|
With<Player>,
|
||||||
>,
|
>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let (mut transform, grav, output) = player.into_inner();
|
let (mut transform, grav, output) = player.into_inner();
|
||||||
let is_grounded = output.map(|o| o.grounded).unwrap_or(false);
|
let is_grounded = output.map(|o| o.grounded).unwrap_or(false);
|
||||||
|
|
||||||
if !is_grounded {
|
if !is_grounded
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(grav_dir) = grav.0 else {
|
let Some(grav_dir) = grav.0
|
||||||
|
else
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ use crate::{
|
|||||||
|
|
||||||
pub struct ShipPlugin;
|
pub struct ShipPlugin;
|
||||||
|
|
||||||
impl Plugin for ShipPlugin {
|
impl Plugin for ShipPlugin
|
||||||
fn build(&self, app: &mut App) {
|
{
|
||||||
|
fn build(&self, app: &mut App)
|
||||||
|
{
|
||||||
app.add_systems(Update, spawn_ship.in_set(PlayStartupSystems));
|
app.add_systems(Update, spawn_ship.in_set(PlayStartupSystems));
|
||||||
|
|
||||||
app.add_systems(Update, ship_controls.in_set(PlaySystems));
|
app.add_systems(Update, ship_controls.in_set(PlaySystems));
|
||||||
@@ -22,7 +24,8 @@ impl Plugin for ShipPlugin {
|
|||||||
#[derive(Resource, Debug, Reflect)]
|
#[derive(Resource, Debug, Reflect)]
|
||||||
struct ShipMesh(Handle<Scene>);
|
struct ShipMesh(Handle<Scene>);
|
||||||
|
|
||||||
fn spawn_ship(mut commads: Commands, assets: Res<AssetServer>) {
|
fn spawn_ship(mut commads: Commands, assets: Res<AssetServer>)
|
||||||
|
{
|
||||||
let scene = assets.load(GltfAssetLabel::Scene(0).from_asset("models/Ship.glb"));
|
let scene = assets.load(GltfAssetLabel::Scene(0).from_asset("models/Ship.glb"));
|
||||||
|
|
||||||
commads.insert_resource(ShipMesh(scene.clone()));
|
commads.insert_resource(ShipMesh(scene.clone()));
|
||||||
@@ -46,37 +49,50 @@ fn spawn_ship(mut commads: Commands, assets: Res<AssetServer>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn ship_controls(
|
fn ship_controls(
|
||||||
ship_query: Single<(&Transform, &mut Velocity, &mut Damping), With<Ship>>,
|
ship_query: Single<(&Transform, &mut Velocity), With<Ship>>,
|
||||||
key: Res<ButtonInput<KeyCode>>,
|
key: Res<ButtonInput<KeyCode>>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
mouse_motion: EventReader<MouseMotion>,
|
mouse_motion: MessageReader<MouseMotion>,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let (transform, mut vel, mut damp) = ship_query.into_inner();
|
let (transform, mut vel, mut damp) = ship_query.into_inner();
|
||||||
|
|
||||||
let mut move_vec = Vec3::ZERO;
|
let mut move_vec = Vec3::ZERO;
|
||||||
|
|
||||||
if key.pressed(KeyCode::KeyW) {
|
if key.pressed(KeyCode::KeyW)
|
||||||
|
{
|
||||||
move_vec.z = -1.0;
|
move_vec.z = -1.0;
|
||||||
} else if key.pressed(KeyCode::KeyS) {
|
}
|
||||||
|
else if key.pressed(KeyCode::KeyS)
|
||||||
|
{
|
||||||
move_vec.z = 1.0;
|
move_vec.z = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if key.pressed(KeyCode::KeyA) {
|
if key.pressed(KeyCode::KeyA)
|
||||||
|
{
|
||||||
move_vec.x = -1.0;
|
move_vec.x = -1.0;
|
||||||
} else if key.pressed(KeyCode::KeyD) {
|
}
|
||||||
|
else if key.pressed(KeyCode::KeyD)
|
||||||
|
{
|
||||||
move_vec.x = 1.0;
|
move_vec.x = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if key.pressed(KeyCode::Space) {
|
if key.pressed(KeyCode::Space)
|
||||||
|
{
|
||||||
move_vec.y = 1.0;
|
move_vec.y = 1.0;
|
||||||
} else if key.pressed(KeyCode::ShiftLeft) {
|
}
|
||||||
|
else if key.pressed(KeyCode::ShiftLeft)
|
||||||
|
{
|
||||||
move_vec.y = -1.0;
|
move_vec.y = -1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if key.pressed(KeyCode::ControlLeft) {
|
if key.pressed(KeyCode::ControlLeft)
|
||||||
|
{
|
||||||
damp.linear_damping = 0.8;
|
damp.linear_damping = 0.8;
|
||||||
damp.angular_damping = 0.8;
|
damp.angular_damping = 0.8;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
damp.linear_damping = 0.0;
|
damp.linear_damping = 0.0;
|
||||||
damp.angular_damping = 0.0;
|
damp.angular_damping = 0.0;
|
||||||
}
|
}
|
||||||
@@ -84,11 +100,16 @@ fn ship_controls(
|
|||||||
const ROLL_SPEED: f32 = 1.0;
|
const ROLL_SPEED: f32 = 1.0;
|
||||||
const DEAD_ZONE: f32 = 0.1;
|
const DEAD_ZONE: f32 = 0.1;
|
||||||
const INPUT_CURVE: f32 = 3.0;
|
const INPUT_CURVE: f32 = 3.0;
|
||||||
let yaw = if key.pressed(KeyCode::KeyQ) {
|
let yaw = if key.pressed(KeyCode::KeyQ)
|
||||||
|
{
|
||||||
Vec3::Y * ROLL_SPEED
|
Vec3::Y * ROLL_SPEED
|
||||||
} else if key.pressed(KeyCode::KeyE) {
|
}
|
||||||
|
else if key.pressed(KeyCode::KeyE)
|
||||||
|
{
|
||||||
Vec3::Y * -ROLL_SPEED
|
Vec3::Y * -ROLL_SPEED
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Vec3::ZERO
|
Vec3::ZERO
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -110,22 +131,33 @@ fn ship_controls(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dev-viz")]
|
#[cfg(feature = "dev-viz")]
|
||||||
fn ship_debug(mut gizmos: Gizmos, ship: Single<&Transform, With<Ship>>) {
|
fn ship_debug(mut gizmos: Gizmos, ship: Single<&Transform, With<Ship>>)
|
||||||
|
{
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
let base = ship.translation.floor();
|
let base = ship.translation.floor();
|
||||||
const GRID: Range<i32> = -10..10;
|
const GRID: Range<i32> = -10..10;
|
||||||
for x in GRID {
|
for x in GRID
|
||||||
for y in GRID {
|
{
|
||||||
for z in GRID {
|
for y in GRID
|
||||||
|
{
|
||||||
|
for z in GRID
|
||||||
|
{
|
||||||
let p = base + Vec3::new(x as f32, y as f32, z as f32);
|
let p = base + Vec3::new(x as f32, y as f32, z as f32);
|
||||||
let color = if x == 0 && y == 0 {
|
let color = if x == 0 && y == 0
|
||||||
|
{
|
||||||
LinearRgba::BLUE
|
LinearRgba::BLUE
|
||||||
} else if x == 0 && z == 0 {
|
}
|
||||||
|
else if x == 0 && z == 0
|
||||||
|
{
|
||||||
LinearRgba::GREEN
|
LinearRgba::GREEN
|
||||||
} else if y == 0 && z == 0 {
|
}
|
||||||
|
else if y == 0 && z == 0
|
||||||
|
{
|
||||||
LinearRgba::RED
|
LinearRgba::RED
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
LinearRgba::gray(0.2).with_alpha(0.2)
|
LinearRgba::gray(0.2).with_alpha(0.2)
|
||||||
};
|
};
|
||||||
gizmos.sphere(p, 0.01, color);
|
gizmos.sphere(p, 0.01, color);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use bevy::{input::mouse::MouseMotion, prelude::*};
|
use bevy::{input::mouse::MouseMotion, prelude::*};
|
||||||
|
|
||||||
pub fn get_mouse_delta(mut mouse_motion: EventReader<MouseMotion>) -> Vec2 {
|
pub fn get_mouse_delta(mut mouse_motion: MessageReader<MouseMotion>) -> Vec2
|
||||||
|
{
|
||||||
let mut delta = Vec2::ZERO;
|
let mut delta = Vec2::ZERO;
|
||||||
for e in mouse_motion.read() {
|
for e in mouse_motion.read()
|
||||||
|
{
|
||||||
delta += e.delta;
|
delta += e.delta;
|
||||||
}
|
}
|
||||||
return delta;
|
return delta;
|
||||||
|
|||||||
Reference in New Issue
Block a user