From f85b5cf7af6040e554a090d1e117208074c221b8 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 1 Jan 2021 18:31:38 +0100 Subject: [PATCH] Improved camera control --- src/player.rs | 66 +++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/src/player.rs b/src/player.rs index 42534e8..d112119 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,4 +1,4 @@ -use bevy::{input::mouse::MouseMotion, math::clamp, prelude::*}; +use bevy::{input::mouse::MouseMotion, prelude::*}; use bevy_rapier3d::{ na::Matrix3x1, physics::RigidBodyHandleComponent, @@ -25,32 +25,33 @@ struct State { mouse_motion_event_reader: EventReader, } -struct Player { - /// The current pitch of the FlyCamera in degrees. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html) - pitch: f32, - /// The current pitch of the FlyCamera in degrees. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html) - yaw: f32, -} +#[derive(Default)] +struct Player; const PLAYER_SPEED: f32 = 320.0; -const MOUSE_SENSITIVITY: f32 = 6.0; +const MOUSE_SENSITIVITY: f32 = 1.0; -impl Player { - fn create() -> Self { - Self { - pitch: 0.0, - yaw: 0.0, - } - } -} - -fn init_player(commands: &mut Commands) { +fn init_player( + commands: &mut Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { commands .spawn(Camera3dBundle { - transform: Transform::from_translation(Vec3::new(0.0, 3.0, 3.0)), + transform: Transform::from_translation(Vec3::new(0.0, 1.0, 3.0)), ..Default::default() }) - .with(Player::create()) + .with(Player::default()); + + // TODO: temporarily create a separate bundle for movement, to test mouse look + commands + .spawn(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Cube { size: 0.25 })), + material: materials.add(Color::rgb(0.0, 1.0, 0.3).into()), + transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)), + ..Default::default() + }) + .with(Player::default()) .with( RigidBodyBuilder::new_dynamic() .translation(0.0, 3.0, 0.0) @@ -111,9 +112,8 @@ fn movement_axis(input: &Res>, plus: KeyCode, minus: KeyCode) -> fn player_look_system( time: Res