First person camera
Input States
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
use std::f32::EPSILON;
|
||||
use std::f32::{EPSILON, consts::FRAC_PI_2};
|
||||
|
||||
use bevy::{input::mouse::MouseMotion, prelude::*};
|
||||
use bevy_rapier3d::prelude::*;
|
||||
|
||||
use crate::{
|
||||
components::{
|
||||
camera::CameraPitch,
|
||||
player::{GravityDirection, JumpSpeed, MoveSpeed, PlayerDrag, PlayerForce, PlayerMotion, PlayerVelocity},
|
||||
tags::Player,
|
||||
},
|
||||
utils::{
|
||||
input::get_mouse_delta,
|
||||
rotation::{get_alignment_rotation, get_alignment_rotation_preserve_twist},
|
||||
},
|
||||
states::input::PlayerInputSystems,
|
||||
utils::{input::get_mouse_delta, rotation::get_alignment_rotation_preserve_twist},
|
||||
};
|
||||
|
||||
pub struct PlayerPlugin;
|
||||
@@ -24,9 +23,6 @@ impl Plugin for PlayerPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PlayerInputSystems;
|
||||
|
||||
fn apply_forces(player: Single<(&mut PlayerVelocity, &PlayerForce), With<Player>>, time: Res<Time>) {
|
||||
let (mut vel, force) = player.into_inner();
|
||||
|
||||
@@ -129,12 +125,14 @@ fn keyboard_input(
|
||||
|
||||
fn player_look(
|
||||
mut player: Single<&mut Transform, With<Player>>,
|
||||
mut cam_pitch: Single<&mut CameraPitch>,
|
||||
mouse_motion: EventReader<MouseMotion>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let delta = get_mouse_delta(mouse_motion) * -time.delta_secs();
|
||||
let up = player.up();
|
||||
player.rotate_axis(up, delta.x);
|
||||
cam_pitch.0 = (cam_pitch.0 + delta.y).clamp(-FRAC_PI_2 + 0.001, FRAC_PI_2 - 0.001);
|
||||
}
|
||||
|
||||
fn align_with_gravity(
|
||||
|
||||
Reference in New Issue
Block a user