Speed and weapon bobbing change on sprint, crouch and aim
This commit is contained in:
parent
dd9496d110
commit
d1c5cdd9b9
@ -27,6 +27,7 @@ pub struct PlayerFiringInfo {
|
|||||||
/// This is specifically for situations where the player is holding a gun that is stuck against a wall, and should not be false
|
/// This is specifically for situations where the player is holding a gun that is stuck against a wall, and should not be false
|
||||||
/// until the gun stops colliding with the wall.
|
/// until the gun stops colliding with the wall.
|
||||||
pub gun_colliding_with_object: bool,
|
pub gun_colliding_with_object: bool,
|
||||||
|
pub is_aiming: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PlayerFiringInfo {
|
impl Default for PlayerFiringInfo {
|
||||||
@ -40,6 +41,7 @@ impl Default for PlayerFiringInfo {
|
|||||||
gun_ready_pose: GunReadyPose::LowReady,
|
gun_ready_pose: GunReadyPose::LowReady,
|
||||||
is_inspecting: false,
|
is_inspecting: false,
|
||||||
gun_colliding_with_object: false,
|
gun_colliding_with_object: false,
|
||||||
|
is_aiming: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_rapier3d::dynamics::Velocity;
|
use bevy_rapier3d::dynamics::Velocity;
|
||||||
|
|
||||||
use crate::comps::core::markers::{player::Player, holdable::InPlayerHands, firearm_scene::FirearmScene};
|
use crate::{comps::core::markers::{player::Player, holdable::InPlayerHands, firearm_scene::FirearmScene}, logic::core::guns::player_firing::PlayerFiringInfo};
|
||||||
|
|
||||||
use super::{player_movement::{PlayerLinearYState, PlayerMovementInput, PlayerLinearXZState}, camera_player_sync::HandSwaying};
|
use super::{player_movement::{PlayerLinearYState, PlayerMovementInput, PlayerLinearXZState}, camera_player_sync::HandSwaying};
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ const BOBBING_LIMIT: Vec3 = Vec3 { x: 0.01, y: 0.01, z: 0.01 };
|
|||||||
const BOBBING_ROT_MULTIPLIER: Vec3 = Vec3 { x: 2.0, y: 2.0, z: 2.0};
|
const BOBBING_ROT_MULTIPLIER: Vec3 = Vec3 { x: 2.0, y: 2.0, z: 2.0};
|
||||||
|
|
||||||
pub fn hand_bobbing_on_player_movement(
|
pub fn hand_bobbing_on_player_movement(
|
||||||
player_query: Query<(&Velocity, &PlayerLinearYState, &PlayerLinearXZState, &PlayerMovementInput), With<Player>>,
|
player_query: Query<(&Velocity, &PlayerLinearYState, &PlayerLinearXZState, &PlayerMovementInput, &PlayerFiringInfo), With<Player>>,
|
||||||
|
|
||||||
in_player_hands_query: Query<(Entity, &HandSwaying), With<InPlayerHands>>,
|
in_player_hands_query: Query<(Entity, &HandSwaying), With<InPlayerHands>>,
|
||||||
mut firearm_scene_query: Query<(&Parent, &mut Transform, &mut HandBobbing), (With<Handle<Scene>>, With<FirearmScene>)>,
|
mut firearm_scene_query: Query<(&Parent, &mut Transform, &mut HandBobbing), (With<Handle<Scene>>, With<FirearmScene>)>,
|
||||||
@ -29,8 +29,19 @@ pub fn hand_bobbing_on_player_movement(
|
|||||||
for (in_player_hands, hand_swaying) in in_player_hands_query.iter() {
|
for (in_player_hands, hand_swaying) in in_player_hands_query.iter() {
|
||||||
for (firearm_scene_parent, mut firearm_scene_transform, mut hand_bobbing) in firearm_scene_query.iter_mut() {
|
for (firearm_scene_parent, mut firearm_scene_transform, mut hand_bobbing) in firearm_scene_query.iter_mut() {
|
||||||
if in_player_hands == firearm_scene_parent.get() {
|
if in_player_hands == firearm_scene_parent.get() {
|
||||||
for (player_velocity, player_linear_y_state, player_linear_xz_state, player_movement_input) in player_query.iter() {
|
for (player_velocity, player_linear_y_state, player_linear_xz_state, player_movement_input, player_firing_info) in player_query.iter() {
|
||||||
|
let bobbing_limit = BOBBING_LIMIT *
|
||||||
|
if player_linear_xz_state.is_sprinting() { 2.0 } else { 1.0 } *
|
||||||
|
if player_linear_xz_state.is_crouched() { 0.9 } else { 1.0 } *
|
||||||
|
if player_firing_info.is_aiming { 0.6 } else { 1.0 };
|
||||||
|
let travel_limit = TRAVEL_LIMIT *
|
||||||
|
if player_linear_xz_state.is_sprinting() { 1.0 } else { 1.0 } *
|
||||||
|
if player_linear_xz_state.is_crouched() { 0.9 } else { 1.0 } *
|
||||||
|
if player_firing_info.is_aiming { 0.6 } else { 1.0 };
|
||||||
|
let bobbing_rot_multiplier = BOBBING_ROT_MULTIPLIER *
|
||||||
|
if player_linear_xz_state.is_sprinting() { 2.0 } else { 1.0 } *
|
||||||
|
if player_linear_xz_state.is_crouched() { 0.9 } else { 1.0 } *
|
||||||
|
if player_firing_info.is_aiming { 0.6 } else { 1.0 };
|
||||||
// Speed curve
|
// Speed curve
|
||||||
hand_bobbing.speed_curve += time.delta_seconds() *
|
hand_bobbing.speed_curve += time.delta_seconds() *
|
||||||
if player_linear_y_state.is_grounded(&0.25) {
|
if player_linear_y_state.is_grounded(&0.25) {
|
||||||
@ -38,28 +49,28 @@ pub fn hand_bobbing_on_player_movement(
|
|||||||
} else { 1.0 };
|
} else { 1.0 };
|
||||||
|
|
||||||
// Bobbing translation
|
// Bobbing translation
|
||||||
hand_bobbing.bob_position.x = (hand_bobbing.speed_curve.cos() * BOBBING_LIMIT.x * (
|
hand_bobbing.bob_position.x = (hand_bobbing.speed_curve.cos() * bobbing_limit.x * (
|
||||||
if player_linear_y_state.is_grounded(&0.25) { 1.0 } else { 0.0 }
|
if player_linear_y_state.is_grounded(&0.25) { 1.0 } else { 0.0 }
|
||||||
)) - (player_movement_input.get_horizontal_value_normalized() * TRAVEL_LIMIT.x);
|
)) - (player_movement_input.get_horizontal_value_normalized() * travel_limit.x);
|
||||||
|
|
||||||
hand_bobbing.bob_position.y = (hand_bobbing.speed_curve.sin() * BOBBING_LIMIT.y) - (player_velocity.linvel.y * TRAVEL_LIMIT.y);
|
hand_bobbing.bob_position.y = (hand_bobbing.speed_curve.sin() * bobbing_limit.y) - (player_velocity.linvel.y * travel_limit.y);
|
||||||
|
|
||||||
hand_bobbing.bob_position.z = player_movement_input.get_vertical_value_normalized() * TRAVEL_LIMIT.z * -1.0;
|
hand_bobbing.bob_position.z = player_movement_input.get_vertical_value_normalized() * travel_limit.z * -1.0;
|
||||||
|
|
||||||
// Bobbing rotation
|
// Bobbing rotation
|
||||||
let input = player_movement_input.get_input();
|
let input = player_movement_input.get_input();
|
||||||
hand_bobbing.bob_euler_rotation.x = if input == Vec2::ZERO {
|
hand_bobbing.bob_euler_rotation.x = if input == Vec2::ZERO {
|
||||||
BOBBING_ROT_MULTIPLIER.x * ((hand_bobbing.speed_curve * 2.0).sin() / 2.0)
|
bobbing_rot_multiplier.x * ((hand_bobbing.speed_curve * 2.0).sin() / 2.0)
|
||||||
} else {
|
} else {
|
||||||
BOBBING_ROT_MULTIPLIER.x * (hand_bobbing.speed_curve * 2.0).sin()
|
bobbing_rot_multiplier.x * (hand_bobbing.speed_curve * 2.0).sin()
|
||||||
};
|
};
|
||||||
|
|
||||||
hand_bobbing.bob_euler_rotation.y = if input == Vec2::ZERO { 0.0 } else {
|
hand_bobbing.bob_euler_rotation.y = if input == Vec2::ZERO { 0.0 } else {
|
||||||
BOBBING_ROT_MULTIPLIER.y * hand_bobbing.speed_curve.cos()
|
bobbing_rot_multiplier.y * hand_bobbing.speed_curve.cos()
|
||||||
};
|
};
|
||||||
|
|
||||||
hand_bobbing.bob_euler_rotation.z = if input == Vec2::ZERO { 0.0 } else {
|
hand_bobbing.bob_euler_rotation.z = if input == Vec2::ZERO { 0.0 } else {
|
||||||
BOBBING_ROT_MULTIPLIER.z * hand_bobbing.speed_curve.cos() * input.x
|
bobbing_rot_multiplier.z * hand_bobbing.speed_curve.cos() * input.x
|
||||||
};
|
};
|
||||||
|
|
||||||
// Applying bobbing + sway to actual transform
|
// Applying bobbing + sway to actual transform
|
||||||
|
@ -203,6 +203,7 @@ pub fn capture_hand_usage(
|
|||||||
&& !resources.game_ui_state.any_window() && !player_linear_xz_state.is_sprinting()
|
&& !resources.game_ui_state.any_window() && !player_linear_xz_state.is_sprinting()
|
||||||
&& !player_firing_info.gun_colliding_with_object
|
&& !player_firing_info.gun_colliding_with_object
|
||||||
{
|
{
|
||||||
|
player_firing_info.is_aiming = true;
|
||||||
player_firing_info.gun_ready_pose = GunReadyPose::HighReady;
|
player_firing_info.gun_ready_pose = GunReadyPose::HighReady;
|
||||||
let rotation_lerp_quat = in_hand_transform.rotation.lerp(
|
let rotation_lerp_quat = in_hand_transform.rotation.lerp(
|
||||||
firearm_data.final_aimed_rotation + resources.player_settings.rot_aimed_offset,
|
firearm_data.final_aimed_rotation + resources.player_settings.rot_aimed_offset,
|
||||||
@ -229,6 +230,7 @@ pub fn capture_hand_usage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
player_firing_info.is_aiming = false;
|
||||||
in_hand_transform.rotation = in_hand_transform.rotation.lerp(
|
in_hand_transform.rotation = in_hand_transform.rotation.lerp(
|
||||||
firearm_data.rotation_offset + resources.player_settings.rot_offset,
|
firearm_data.rotation_offset + resources.player_settings.rot_offset,
|
||||||
(resources.time.delta_seconds()
|
(resources.time.delta_seconds()
|
||||||
|
@ -151,6 +151,11 @@ pub fn move_player(
|
|||||||
} else {
|
} else {
|
||||||
1.0
|
1.0
|
||||||
};
|
};
|
||||||
|
let aimed_in_multiplier = if player_firing_info.is_aiming {
|
||||||
|
0.6
|
||||||
|
} else {
|
||||||
|
1.0
|
||||||
|
};
|
||||||
let local_z = player_transform.local_z();
|
let local_z = player_transform.local_z();
|
||||||
let forward = -Vec3::new(local_z.x, 0.0, local_z.z);
|
let forward = -Vec3::new(local_z.x, 0.0, local_z.z);
|
||||||
let right = Vec3::new(local_z.z, 0.0, -local_z.x);
|
let right = Vec3::new(local_z.z, 0.0, -local_z.x);
|
||||||
@ -167,7 +172,7 @@ pub fn move_player(
|
|||||||
forward,
|
forward,
|
||||||
player_velocity.linvel,
|
player_velocity.linvel,
|
||||||
time.delta_seconds(),
|
time.delta_seconds(),
|
||||||
sprint_multiplier * crouch_multiplier,
|
sprint_multiplier * crouch_multiplier * aimed_in_multiplier,
|
||||||
player_values_state.player_acceleration,
|
player_values_state.player_acceleration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -182,7 +187,7 @@ pub fn move_player(
|
|||||||
-forward,
|
-forward,
|
||||||
player_velocity.linvel,
|
player_velocity.linvel,
|
||||||
time.delta_seconds(),
|
time.delta_seconds(),
|
||||||
crouch_multiplier,
|
crouch_multiplier * aimed_in_multiplier,
|
||||||
player_values_state.player_acceleration,
|
player_values_state.player_acceleration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -202,7 +207,7 @@ pub fn move_player(
|
|||||||
* crouch_multiplier
|
* crouch_multiplier
|
||||||
} else {
|
} else {
|
||||||
player_values_state.player_lateral_acceleration_multiplier
|
player_values_state.player_lateral_acceleration_multiplier
|
||||||
* crouch_multiplier
|
* crouch_multiplier * aimed_in_multiplier
|
||||||
},
|
},
|
||||||
player_values_state.player_acceleration,
|
player_values_state.player_acceleration,
|
||||||
);
|
);
|
||||||
@ -223,7 +228,7 @@ pub fn move_player(
|
|||||||
* crouch_multiplier
|
* crouch_multiplier
|
||||||
} else {
|
} else {
|
||||||
player_values_state.player_lateral_acceleration_multiplier
|
player_values_state.player_lateral_acceleration_multiplier
|
||||||
* crouch_multiplier
|
* crouch_multiplier * aimed_in_multiplier
|
||||||
},
|
},
|
||||||
player_values_state.player_acceleration,
|
player_values_state.player_acceleration,
|
||||||
);
|
);
|
||||||
@ -250,9 +255,10 @@ pub fn move_player(
|
|||||||
player_velocity.linvel.x = player_values_state.max_linear_player_velocity
|
player_velocity.linvel.x = player_values_state.max_linear_player_velocity
|
||||||
* crouch_multiplier
|
* crouch_multiplier
|
||||||
* sprint_multiplier
|
* sprint_multiplier
|
||||||
|
* aimed_in_multiplier
|
||||||
} else {
|
} else {
|
||||||
player_velocity.linvel.x =
|
player_velocity.linvel.x =
|
||||||
player_values_state.max_linear_player_velocity * -1.0 * crouch_multiplier
|
player_values_state.max_linear_player_velocity * -1.0 * crouch_multiplier * aimed_in_multiplier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if player_velocity.linvel.z.abs()
|
if player_velocity.linvel.z.abs()
|
||||||
@ -261,10 +267,10 @@ pub fn move_player(
|
|||||||
let positive = player_velocity.linvel.z.is_sign_positive();
|
let positive = player_velocity.linvel.z.is_sign_positive();
|
||||||
if positive {
|
if positive {
|
||||||
player_velocity.linvel.z =
|
player_velocity.linvel.z =
|
||||||
player_values_state.max_linear_player_velocity * crouch_multiplier * sprint_multiplier
|
player_values_state.max_linear_player_velocity * crouch_multiplier * sprint_multiplier * aimed_in_multiplier
|
||||||
} else {
|
} else {
|
||||||
player_velocity.linvel.z =
|
player_velocity.linvel.z =
|
||||||
player_values_state.max_linear_player_velocity * -1.0 * crouch_multiplier * sprint_multiplier
|
player_values_state.max_linear_player_velocity * -1.0 * crouch_multiplier * sprint_multiplier * aimed_in_multiplier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if player_velocity.linvel.x > -1.0
|
if player_velocity.linvel.x > -1.0
|
||||||
|
Loading…
Reference in New Issue
Block a user