Make constants actually const
This commit is contained in:
parent
0db4cdafb7
commit
b5e29b10a6
1 changed files with 12 additions and 17 deletions
|
@ -6,12 +6,6 @@ use bevy_rapier3d::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Player {
|
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)
|
/// The current pitch of the FlyCamera in degrees. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html)
|
||||||
pub pitch: f32,
|
pub pitch: f32,
|
||||||
/// The current pitch of the FlyCamera in degrees. This value is always up-to-date, enforced by [FlyCameraPlugin](struct.FlyCameraPlugin.html)
|
/// 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,
|
pub velocity: Vec3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PLAYER_SPEED: f32 = 15.0;
|
||||||
|
const PLAYER_FRICTION: f32 = 1.0;
|
||||||
|
const MOUSE_SENSITIVITY: f32 = 6.0;
|
||||||
|
|
||||||
impl Player {
|
impl Player {
|
||||||
pub fn create() -> Self {
|
pub fn create() -> Self {
|
||||||
Self {
|
Self {
|
||||||
speed: 15.,
|
|
||||||
sensitivity: 6.0,
|
|
||||||
friction: 1.0,
|
|
||||||
pitch: 0.0,
|
pitch: 0.0,
|
||||||
yaw: 0.0,
|
yaw: 0.0,
|
||||||
velocity: Vec3::zero(),
|
velocity: Vec3::zero(),
|
||||||
|
@ -76,13 +71,13 @@ fn camera_movement_system(
|
||||||
+ (forward_vector(&rotation) * axis_v)
|
+ (forward_vector(&rotation) * axis_v)
|
||||||
+ (Vec3::unit_y() * axis_float);
|
+ (Vec3::unit_y() * axis_float);
|
||||||
let accel: Vec3 = if accel.length() != 0.0 {
|
let accel: Vec3 = if accel.length() != 0.0 {
|
||||||
accel.normalize() * player.speed
|
accel.normalize() * PLAYER_SPEED
|
||||||
} else {
|
} else {
|
||||||
Vec3::zero()
|
Vec3::zero()
|
||||||
};
|
};
|
||||||
|
|
||||||
let friction: Vec3 = if player.velocity.length() != 0.0 {
|
let friction: Vec3 = if player.velocity.length() != 0.0 {
|
||||||
player.velocity.normalize() * -1.0 * player.friction
|
player.velocity.normalize() * -1.0 * PLAYER_FRICTION
|
||||||
} else {
|
} else {
|
||||||
Vec3::zero()
|
Vec3::zero()
|
||||||
};
|
};
|
||||||
|
@ -122,16 +117,16 @@ fn mouse_motion_system(
|
||||||
return;
|
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();
|
let body: &mut RigidBody = bodies.get_mut(handle.handle()).unwrap();
|
||||||
options.yaw -= delta.x * options.sensitivity * time.delta_seconds();
|
player.yaw -= delta.x * MOUSE_SENSITIVITY * time.delta_seconds();
|
||||||
options.pitch += delta.y * options.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);
|
// println!("pitch: {}, yaw: {}", options.pitch, options.yaw);
|
||||||
|
|
||||||
let yaw_radians = options.yaw.to_radians();
|
let yaw_radians = player.yaw.to_radians();
|
||||||
let pitch_radians = options.pitch.to_radians();
|
let pitch_radians = player.pitch.to_radians();
|
||||||
|
|
||||||
transform.rotation = Quat::from_axis_angle(Vec3::unit_y(), yaw_radians)
|
transform.rotation = Quat::from_axis_angle(Vec3::unit_y(), yaw_radians)
|
||||||
* Quat::from_axis_angle(-Vec3::unit_x(), pitch_radians)
|
* Quat::from_axis_angle(-Vec3::unit_x(), pitch_radians)
|
||||||
|
|
Loading…
Reference in a new issue