can rotate view via TAB
This commit is contained in:
@@ -34,14 +34,14 @@ struct PlayerSpawned {
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
struct PlayerMovement {
|
||||
any_direction: bool,
|
||||
pub struct PlayerMovement {
|
||||
pub any_direction: bool,
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.init_resource::<PlayerSpawned>();
|
||||
app.init_resource::<PlayerMovement>();
|
||||
app.add_systems(Startup, initial_grab_cursor);
|
||||
app.add_systems(Startup, (initial_grab_cursor, cursor_recenter));
|
||||
app.add_systems(
|
||||
Update,
|
||||
(
|
||||
@@ -131,6 +131,10 @@ fn rotate_view(
|
||||
// todo: Put the player head as a child of the rig to avoid this mess:
|
||||
mut player: Query<&mut Transform, With<PlayerRig>>,
|
||||
) {
|
||||
if controls.keyboard_state.view_mode {
|
||||
return;
|
||||
}
|
||||
|
||||
for mut tr in &mut player {
|
||||
tr.rotate_y(controls.keyboard_state.look_dir.x * -0.001);
|
||||
|
||||
@@ -142,6 +146,12 @@ fn rotate_view(
|
||||
controls.keyboard_state.look_dir = Vec2::ZERO;
|
||||
}
|
||||
|
||||
fn cursor_recenter(mut q_windows: Query<&mut Window, With<PrimaryWindow>>) {
|
||||
let mut primary_window = q_windows.single_mut();
|
||||
let center = Vec2::new(primary_window.width() / 2.0, primary_window.height() / 2.0);
|
||||
primary_window.set_cursor_position(Some(center));
|
||||
}
|
||||
|
||||
fn toggle_grab_cursor(window: &mut Window) {
|
||||
match window.cursor_options.grab_mode {
|
||||
CursorGrabMode::None => {
|
||||
|
||||
Reference in New Issue
Block a user