mouse movement now changes player orientation relatively, not absolutely
This commit is contained in:
parent
0456b8506c
commit
6e3d958638
|
@ -24,25 +24,6 @@ impl Plugin for CameraControllerPlugin {
|
|||
// it because it felt nice.
|
||||
pub const RADIANS_PER_DOT: f32 = 1.0 / 180.0;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct CameraController {
|
||||
pub enabled: bool,
|
||||
pub initialized: bool,
|
||||
pub pitch: f32,
|
||||
pub yaw: f32,
|
||||
}
|
||||
|
||||
impl Default for CameraController {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
initialized: false,
|
||||
pitch: 1.0, // pitch=0/yaw=0 -> face sun
|
||||
yaw: 0.3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_camera(
|
||||
mut commands: Commands,
|
||||
) {
|
||||
|
@ -57,7 +38,6 @@ fn setup_camera(
|
|||
transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
},
|
||||
CameraController::default(),
|
||||
BloomSettings {
|
||||
composite_mode: BloomCompositeMode::EnergyConserving,
|
||||
..default()
|
||||
|
@ -67,8 +47,8 @@ fn setup_camera(
|
|||
|
||||
pub fn sync_camera_to_player(
|
||||
settings: Res<settings::Settings>,
|
||||
mut q_camera: Query<&mut Transform, With<CameraController>>,
|
||||
q_playercam: Query<(&actor::Actor, &Transform), (With<actor::PlayerCamera>, Without<actor::PlayerDrivesThis>, Without<CameraController>)>,
|
||||
mut q_camera: Query<&mut Transform, With<Camera>>,
|
||||
q_playercam: Query<(&actor::Actor, &Transform), (With<actor::PlayerCamera>, Without<actor::PlayerDrivesThis>, Without<Camera>)>,
|
||||
) {
|
||||
if q_camera.is_empty() || q_playercam.is_empty() {
|
||||
return;
|
||||
|
@ -126,14 +106,14 @@ fn run_camera_controller(
|
|||
rocket_sound_controller: Query<&AudioSink, With<audio::ComponentRocketSound>>,
|
||||
ion_sound_controller: Query<&AudioSink, With<audio::ComponentIonSound>>,
|
||||
mut q_engine: Query<&mut actor::Engine, With<actor::PlayerDrivesThis>>,
|
||||
mut q_camera: Query<(&mut CameraController, &mut Projection)>,
|
||||
mut q_camera: Query<&mut Projection, With<Camera>>,
|
||||
q_player: Query<&actor::LifeForm, With<actor::Player>>,
|
||||
mut q_playercam: Query<(
|
||||
&mut Transform,
|
||||
&mut actor::Engine,
|
||||
&mut AngularVelocity,
|
||||
&mut LinearVelocity,
|
||||
), (With<actor::PlayerCamera>, Without<actor::PlayerDrivesThis>, Without<CameraController>)>,
|
||||
), (With<actor::PlayerCamera>, Without<actor::PlayerDrivesThis>, Without<Camera>)>,
|
||||
) {
|
||||
let dt = time.delta_seconds();
|
||||
let mut play_thruster_sound = false;
|
||||
|
@ -145,14 +125,10 @@ fn run_camera_controller(
|
|||
}
|
||||
|
||||
if let (
|
||||
Ok((mut controller, mut projection)),
|
||||
Ok(mut projection),
|
||||
Ok(lifeform),
|
||||
Ok((mut player_transform, player_engine, mut angularvelocity, mut v)),
|
||||
) = (q_camera.get_single_mut(), q_player.get_single(), q_playercam.get_single_mut()) {
|
||||
if !controller.enabled {
|
||||
mouse_events.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if angularvelocity.length_squared() > 0.0001 {
|
||||
angularvelocity.x *= 0.98;
|
||||
|
@ -242,11 +218,9 @@ fn run_camera_controller(
|
|||
|
||||
if mouse_delta != Vec2::ZERO {
|
||||
// Apply look update
|
||||
controller.pitch = (controller.pitch
|
||||
+ mouse_delta.y * RADIANS_PER_DOT * settings.mouse_sensitivity)
|
||||
.clamp(-PI / 2., PI / 2.);
|
||||
controller.yaw += mouse_delta.x * RADIANS_PER_DOT * settings.mouse_sensitivity;
|
||||
player_transform.rotation = Quat::from_euler(EulerRot::ZYX, 0.0, -controller.yaw, controller.pitch).normalize();
|
||||
let pitch = (mouse_delta.y * RADIANS_PER_DOT * settings.mouse_sensitivity).clamp(-PI / 2., PI / 2.);
|
||||
let yaw = mouse_delta.x * RADIANS_PER_DOT * settings.mouse_sensitivity;
|
||||
player_transform.rotation *= Quat::from_euler(EulerRot::ZYX, 0.0, -yaw, pitch).normalize();
|
||||
}
|
||||
|
||||
let fov = (lifeform.adrenaline * lifeform.adrenaline * lifeform.adrenaline * 45.0 + 45.0).to_radians();
|
||||
|
|
Loading…
Reference in a new issue