apply smooth torque rather than "teleport" when rotating player
This commit is contained in:
parent
ac3b17badf
commit
2411430799
|
@ -25,11 +25,6 @@ impl Plugin for CameraControllerPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
// Based on Valorant's default sensitivity, not entirely sure why it is exactly 1.0 / 180.0,
|
||||
// but I'm guessing it is a misunderstanding between degrees/radians and then sticking with
|
||||
// it because it felt nice.
|
||||
pub const RADIANS_PER_DOT: f32 = 1.0 / 180.0;
|
||||
|
||||
pub fn setup_camera(
|
||||
mut commands: Commands,
|
||||
) {
|
||||
|
@ -131,10 +126,11 @@ fn apply_input_to_player(
|
|||
ion_sound_controller: Query<&AudioSink, With<audio::ComponentIonSound>>,
|
||||
electricmotor_sound_controller: Query<&AudioSink, With<audio::ComponentElectricMotorSound>>,
|
||||
mut q_playercam: Query<(
|
||||
&mut Transform,
|
||||
&Transform,
|
||||
&mut actor::Engine,
|
||||
&mut AngularVelocity,
|
||||
&mut LinearVelocity,
|
||||
&mut ExternalTorque,
|
||||
), (With<actor::PlayerCamera>, Without<Camera>)>,
|
||||
) {
|
||||
let dt = time.delta_seconds();
|
||||
|
@ -146,17 +142,7 @@ fn apply_input_to_player(
|
|||
focused = window_result.unwrap().focused;
|
||||
}
|
||||
|
||||
if let Ok((mut player_transform, mut engine, mut angularvelocity, mut v)) = q_playercam.get_single_mut() {
|
||||
|
||||
if angularvelocity.length_squared() > 0.0001 {
|
||||
angularvelocity.x *= 0.98;
|
||||
angularvelocity.y *= 0.98;
|
||||
angularvelocity.z *= 0.98;
|
||||
}
|
||||
else {
|
||||
angularvelocity.0 = Vec3::splat(0.0);
|
||||
}
|
||||
|
||||
if let Ok((player_transform, mut engine, mut angularvelocity, mut v, mut torque)) = q_playercam.get_single_mut() {
|
||||
// Handle key input
|
||||
let mut axis_input = Vec3::ZERO;
|
||||
if focused {
|
||||
|
@ -231,7 +217,7 @@ fn apply_input_to_player(
|
|||
let mut play_reactionwheel_sound = false;
|
||||
let mut mouse_delta = Vec2::ZERO;
|
||||
let mut pitch_yaw_rot = Vec3::ZERO;
|
||||
let mouseless_sensitivity = 8.0;
|
||||
let mouseless_sensitivity = 40.0;
|
||||
if key_input.pressed(settings.key_mouseup) {
|
||||
pitch_yaw_rot[0] -= mouseless_sensitivity;
|
||||
}
|
||||
|
@ -239,8 +225,7 @@ fn apply_input_to_player(
|
|||
pitch_yaw_rot[0] += mouseless_sensitivity;
|
||||
}
|
||||
if key_input.pressed(settings.key_mouseleft) {
|
||||
pitch_yaw_rot[1] += mouseless_sensitivity;
|
||||
}
|
||||
pitch_yaw_rot[1] += mouseless_sensitivity; }
|
||||
if key_input.pressed(settings.key_mouseright) {
|
||||
pitch_yaw_rot[1] -= mouseless_sensitivity;
|
||||
}
|
||||
|
@ -263,9 +248,18 @@ fn apply_input_to_player(
|
|||
}
|
||||
if pitch_yaw_rot.length_squared() > 0.0001 {
|
||||
play_reactionwheel_sound = true;
|
||||
pitch_yaw_rot *= RADIANS_PER_DOT * settings.mouse_sensitivity;
|
||||
player_transform.rotation *= Quat::from_euler(EulerRot::ZYX,
|
||||
pitch_yaw_rot[2], pitch_yaw_rot[1], pitch_yaw_rot[0]).normalize();
|
||||
pitch_yaw_rot *= settings.mouse_sensitivity * engine.reaction_wheels;
|
||||
torque.apply_torque(player_transform.rotation * Vec3::new(
|
||||
2.0*pitch_yaw_rot[0], pitch_yaw_rot[1], pitch_yaw_rot[2]));
|
||||
angularvelocity.0 *= 0.98;
|
||||
}
|
||||
else {
|
||||
if angularvelocity.length_squared() > 0.0000001 {
|
||||
angularvelocity.0 *= 0.98;
|
||||
}
|
||||
else {
|
||||
angularvelocity.0 = Vec3::splat(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Play sound effects
|
||||
|
|
|
@ -5,8 +5,8 @@ actor 0 0 0 suit
|
|||
oxygen 0.008
|
||||
health 0.3
|
||||
angularmomentum 0 0 0
|
||||
collider mesh
|
||||
thrust 1.2 1 1 1 1.5
|
||||
collider capsule 2 1
|
||||
thrust 1.2 1 1 100 1.5
|
||||
rotationy 0.65
|
||||
engine monopropellant
|
||||
|
||||
|
@ -134,7 +134,7 @@ actor -3300 10 0 pizzeria
|
|||
actor 10 -30 20 MeteorAceGT
|
||||
scale 5
|
||||
vehicle yes
|
||||
thrust 70 13.7 9.4 0.5 20
|
||||
thrust 70 13.7 9.4 50000 20
|
||||
engine ion
|
||||
collider sphere 1.5
|
||||
camdistance 50
|
||||
|
|
|
@ -706,6 +706,10 @@ fn spawn_entities(
|
|||
actor.insert(actor::Player);
|
||||
actor.insert(actor::PlayerCamera);
|
||||
}
|
||||
if state.is_player || state.is_vehicle {
|
||||
// used to apply mouse movement to actor rotation
|
||||
actor.insert(ExternalTorque::ZERO.with_persistence(false));
|
||||
}
|
||||
if state.is_lifeform {
|
||||
actor.insert(actor::LifeForm::default());
|
||||
actor.insert(actor::Suit {
|
||||
|
|
Loading…
Reference in a new issue