From b5e29b10a64539f05b9e6d1143efd9e498a228f7 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 31 Dec 2020 16:54:49 +0100 Subject: [PATCH] Make constants actually const --- src/player.rs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/player.rs b/src/player.rs index 6e1522a..68cedd9 100644 --- a/src/player.rs +++ b/src/player.rs @@ -6,12 +6,6 @@ use bevy_rapier3d::{ }; pub struct Player { - /// The speed the FlyCamera moves at. Defaults to `1.0` - pub speed: f32, - /// The sensitivity of the FlyCamera's motion based on mouse movement. Defaults to `3.0` - pub sensitivity: f32, - /// The amount of deceleration to apply to the camera's motion. Defaults to `1.0` - pub friction: f32, /// The current pitch of the FlyCamera in degrees. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html) pub pitch: f32, /// The current pitch of the FlyCamera in degrees. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html) @@ -20,12 +14,13 @@ pub struct Player { pub velocity: Vec3, } +const PLAYER_SPEED: f32 = 15.0; +const PLAYER_FRICTION: f32 = 1.0; +const MOUSE_SENSITIVITY: f32 = 6.0; + impl Player { pub fn create() -> Self { Self { - speed: 15., - sensitivity: 6.0, - friction: 1.0, pitch: 0.0, yaw: 0.0, velocity: Vec3::zero(), @@ -76,13 +71,13 @@ fn camera_movement_system( + (forward_vector(&rotation) * axis_v) + (Vec3::unit_y() * axis_float); let accel: Vec3 = if accel.length() != 0.0 { - accel.normalize() * player.speed + accel.normalize() * PLAYER_SPEED } else { Vec3::zero() }; let friction: Vec3 = if player.velocity.length() != 0.0 { - player.velocity.normalize() * -1.0 * player.friction + player.velocity.normalize() * -1.0 * PLAYER_FRICTION } else { Vec3::zero() }; @@ -122,16 +117,16 @@ fn mouse_motion_system( return; } - for (mut options, mut transform, handle) in query.iter_mut() { + for (mut player, mut transform, handle) in query.iter_mut() { let body: &mut RigidBody = bodies.get_mut(handle.handle()).unwrap(); - options.yaw -= delta.x * options.sensitivity * time.delta_seconds(); - options.pitch += delta.y * options.sensitivity * time.delta_seconds(); + player.yaw -= delta.x * MOUSE_SENSITIVITY * time.delta_seconds(); + player.pitch += delta.y * MOUSE_SENSITIVITY * time.delta_seconds(); - options.pitch = clamp(options.pitch, -89.9, 89.9); + player.pitch = clamp(player.pitch, -89.9, 89.9); // println!("pitch: {}, yaw: {}", options.pitch, options.yaw); - let yaw_radians = options.yaw.to_radians(); - let pitch_radians = options.pitch.to_radians(); + let yaw_radians = player.yaw.to_radians(); + let pitch_radians = player.pitch.to_radians(); transform.rotation = Quat::from_axis_angle(Vec3::unit_y(), yaw_radians) * Quat::from_axis_angle(-Vec3::unit_x(), pitch_radians)