Added aimed sens, aiming in is smooth now, and fixed aim reticles

This commit is contained in:
Franklin Blanco 2023-09-16 10:56:24 -07:00
parent da6f47e01f
commit 794d8bf4aa
6 changed files with 24 additions and 27 deletions

View File

@ -31,8 +31,6 @@ pub fn capture_input(
KeyCode::W,
KeyCode::C,
KeyCode::Space,
KeyCode::Q,
KeyCode::E,
]) || keyboard_input.any_just_released([
KeyCode::A,
KeyCode::S,
@ -40,8 +38,6 @@ pub fn capture_input(
KeyCode::W,
KeyCode::C,
KeyCode::Space,
KeyCode::Q,
KeyCode::E,
]) {
let player_movement_input = PlayerMovementInput {
up: keyboard_input.just_pressed(KeyCode::Space),
@ -51,8 +47,6 @@ pub fn capture_input(
front: keyboard_input.pressed(KeyCode::W),
back: keyboard_input.pressed(KeyCode::S),
sprint: keyboard_input.pressed(KeyCode::ShiftLeft),
lean_left: keyboard_input.pressed(KeyCode::Q),
lean_right: keyboard_input.pressed(KeyCode::E),
};
move_player(player_movement_input, player_query, time);
}

View File

@ -11,9 +11,9 @@ pub const PLAYER_INITIAL_WEIGHT: f32 = 75.0;
pub const PLAYER_GRAVITY_SCALE: f32 = 4.0;
pub const PLAYER_HEIGHT: f32 = 2.5;
pub const PLAYER_CAMERA_HEIGHT: f32 = 1.0;
pub const PLAYER_CAMERA_HEIGHT: f32 = 1.25;
pub const PLAYER_CROUCH_HEIGHT: f32 = 0.0;
pub const PLAYER_CROUCH_TIME_S: f32 = 0.6;
pub const PLAYER_CROUCH_TIME_S: f32 = 1.25;
pub const PLAYER_LINEAR_DAMPING: f32 = 3.5;
pub const PLAYER_LINEAR_DAMPING_WHILE_JUMPING: f32 = 0.25;

View File

@ -11,7 +11,6 @@ pub fn spawn_firearm_on_player_hands(
asset_server: Res<AssetServer>,
) {
for entity in query.iter() {
println!("A");
let mut firearm_transform = Transform::from_xyz(0.0, 0.0, 0.0);
firearm_transform.rotate_y(utils::rad_deg::radians_from_degrees(
DEFAULT_PLAYER_FIREARM.holdable_object_data().y_rot,

View File

@ -13,13 +13,15 @@ use super::player_movement::PlayerLinearXZState;
pub struct MouseMovementSettings {
pub sensitivity: f32,
pub speed: f32,
pub aimed_sensitivity: f32,
}
impl Default for MouseMovementSettings {
fn default() -> Self {
Self {
sensitivity: 0.0003,
speed: 12.,
speed: 3.0,
aimed_sensitivity: 0.00005,
}
}
}
@ -83,8 +85,14 @@ pub fn follow_cursor_with_camera(
let (mut yaw, mut pitch, _) = player_transform.rotation.to_euler(EulerRot::YXZ);
for motion in motions.iter() {
let window_scale = window.height().min(window.width());
pitch -= (settings.sensitivity * motion.delta.y * window_scale).to_radians();
yaw -= (settings.sensitivity * motion.delta.x * window_scale).to_radians();
if btn.pressed(MouseButton::Right) {
pitch -= (settings.aimed_sensitivity * motion.delta.y * window_scale).to_radians();
yaw -= (settings.aimed_sensitivity * motion.delta.x * window_scale).to_radians();
} else {
pitch -= (settings.sensitivity * motion.delta.y * window_scale).to_radians();
yaw -= (settings.sensitivity * motion.delta.x * window_scale).to_radians();
}
}
pitch = pitch.clamp(-1.54, 1.54);
@ -111,7 +119,3 @@ pub fn follow_cursor_with_camera(
warn!("Primary window not found for `player_look`!");
}
}
fn lerp(final_vec: Vec3, current: Vec3, delta_time: f32, total_time: f32) -> Vec3 {
(final_vec - current) * (delta_time/total_time)
}

View File

@ -5,7 +5,7 @@ use crate::comps::core::markers::player::PlayerHand;
pub fn capture_hand_usage(
mouse_buttons: Res<Input<MouseButton>>,
mut query: Query<&mut Transform, With<PlayerHand>>,
//time: Res<Time>,
time: Res<Time>,
) {
for mut transform in query.iter_mut() {
if mouse_buttons.pressed(MouseButton::Left) {
@ -17,9 +17,16 @@ pub fn capture_hand_usage(
}
// For now just set the transforms
if mouse_buttons.pressed(MouseButton::Right) {
*transform = Transform::from_xyz(0.0, -0.35, -1.5);
let aimed_in = Vec3 { x: -0.003, y: -0.35, z: -1.6};
let mut aimed_in_rot = Quat::default();
aimed_in_rot.x = 0.013;
transform.rotation = transform.rotation.lerp(aimed_in_rot, time.delta_seconds() / 0.1);
transform.translation = transform.translation.lerp(aimed_in, (time.delta_seconds() / 0.1).clamp(0.0, 1.0));
} else {
*transform = Transform::from_xyz(0.6, -0.45, -2.7)
let aimed_in = Vec3 { x: 0.6, y: -0.45, z: -2.7};
let aimed_in_rot = Quat::default();
transform.rotation = transform.rotation.lerp(aimed_in_rot, time.delta_seconds() / 0.1);
transform.translation = transform.translation.lerp(aimed_in, (time.delta_seconds() / 0.1).clamp(0.0, 1.0));
}
}

View File

@ -98,8 +98,6 @@ pub struct PlayerMovementInput {
pub back: bool,
/// LShift (SPRINTING)
pub sprint: bool,
pub lean_left: bool,
pub lean_right: bool,
}
/// Applies game logic to determine how player should move.
@ -123,7 +121,7 @@ pub fn move_player(
mut player_external_force,
mut player_linear_y_state,
mut player_linear_xz_state,
mut player_transform,
player_transform,
mut player_damping,
) in &mut query
{
@ -206,11 +204,6 @@ pub fn move_player(
}
}
if player_movement_input.lean_left {
} else {}
if player_movement_input.up && player_linear_y_state.is_grounded(&PLAYER_JUMP_COOLDOWN_MS) {
player_external_force.impulse = Vec3::new(0.0, PLAYER_JUMP_FORCE, 0.0);
*player_linear_y_state = PlayerLinearYState::Jumping;