This commit is contained in:
LorrensP-2158466
2025-04-05 19:45:58 +02:00
parent e71e840d9f
commit ec5c4b6205
2 changed files with 10 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
use bevy::{prelude::*, window::CursorOptions};
use bevy::prelude::*;
/// Overrides the default Bevy plugins and configures things like the screen settings.
pub(super) fn plugin(app: &mut App) {
@@ -6,13 +6,6 @@ pub(super) fn plugin(app: &mut App) {
DefaultPlugins.set(WindowPlugin {
primary_window: Window {
title: "Among Me".into(),
// This will spawn an invisible window
// The window will be made visible in the make_visible() system after 3 frames.
// This is useful when you want to avoid the white window that shows up before the GPU is ready to render the app.
cursor_options: CursorOptions {
visible: false,
..default()
},
..default()
}
.into(),

View File

@@ -6,7 +6,7 @@ use crate::{
};
use bevy::{
input::mouse::AccumulatedMouseMotion, pbr::NotShadowCaster, prelude::*,
render::view::RenderLayers,
render::view::RenderLayers, window::PrimaryWindow,
};
#[derive(Debug, Component)]
@@ -24,7 +24,7 @@ impl Default for CameraSensitivity {
struct WorldModelCamera;
pub fn plugin(app: &mut App) {
app.add_systems(OnEnter(GameState::Playing), init_player)
app.add_systems(OnEnter(GameState::Playing), (init_player, hide_cursor))
.add_systems(Update, move_camera.run_if(in_state(GameState::Playing)))
.add_systems(
RunFixedMainLoop,
@@ -97,9 +97,14 @@ pub fn init_player(
));
});
}
fn hide_cursor(mut windows: Query<&mut Window, With<PrimaryWindow>>) {
// Query returns one window typically.
for mut window in windows.iter_mut() {
window.cursor_options.visible = false;
}
}
use std::f32::consts::FRAC_PI_2;
const PITCH_LIMIT: f32 = FRAC_PI_2 - 0.01;
const PITCH_LIMIT: f32 = std::f32::consts::FRAC_PI_2 - 0.01;
pub fn move_camera(
accumulated_mouse_motion: Res<AccumulatedMouseMotion>,