WIP crisper camera controls (mouse rot relative instead of absolute)
This commit is contained in:
parent
86999574d1
commit
51059a2856
29
src/actor.rs
29
src/actor.rs
|
@ -39,7 +39,7 @@ impl Plugin for ActorPlugin {
|
|||
update_physics_lifeforms.run_if(game_running),
|
||||
update_power.run_if(game_running),
|
||||
handle_gravity.run_if(game_running),
|
||||
handle_wants_rotation.run_if(game_running),
|
||||
handle_wants_rotation_change.run_if(game_running),
|
||||
handle_wants_acceleration.run_if(game_running).run_if(alive),
|
||||
handle_wants_maxrotation.run_if(game_running),
|
||||
handle_wants_maxvelocity
|
||||
|
@ -185,7 +185,7 @@ pub struct WantsMaxVelocity(pub f64);
|
|||
#[derive(Component)]
|
||||
pub struct WantsToLookAt(pub String);
|
||||
#[derive(Component)]
|
||||
pub struct WantsRotation(pub DQuat);
|
||||
pub struct WantsRotationChange(pub Vec3); // Vec3 = (pitch, yaw, rot)
|
||||
#[derive(Component)]
|
||||
pub struct WantsMatchVelocityWith(pub String);
|
||||
#[derive(Component)]
|
||||
|
@ -586,6 +586,7 @@ pub fn handle_vehicle_enter_exit(
|
|||
*driver_vis = Visibility::Hidden; //seems to have no effect...
|
||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
||||
commands.entity(driver).remove::<PlayerCamera>();
|
||||
commands.entity(driver).remove::<WantsRotationChange>();
|
||||
commands.entity(driver).remove::<Collider>();
|
||||
commands.entity(driver).insert(JustNowEnteredVehicle);
|
||||
commands
|
||||
|
@ -717,9 +718,27 @@ fn handle_wants_maxvelocity(
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_wants_rotation(mut q_actor: Query<(&mut Rotation, &WantsRotation)>) {
|
||||
for (mut rot, setrot) in &mut q_actor {
|
||||
**rot = setrot.0;
|
||||
fn handle_wants_rotation_change(mut q_actor: Query<(&mut Rotation, &mut WantsRotationChange)>) {
|
||||
for (mut rot, mut change_rot) in &mut q_actor {
|
||||
if change_rot.0 == Vec3::ZERO {
|
||||
continue;
|
||||
}
|
||||
|
||||
let actual_change_rot = change_rot.0.clamp_length_max(0.10);
|
||||
for axis in 0..3 {
|
||||
let original = change_rot.0[axis];
|
||||
change_rot.0[axis] = 0.90 * change_rot.0[axis] - actual_change_rot[axis];
|
||||
if original.signum() != change_rot.0[axis].signum() {
|
||||
change_rot.0[axis] = 0.0;
|
||||
}
|
||||
}
|
||||
let change = DQuat::from_euler(
|
||||
EulerRot::XYZ,
|
||||
actual_change_rot[0] as f64,
|
||||
actual_change_rot[1] as f64,
|
||||
actual_change_rot[2] as f64,
|
||||
);
|
||||
**rot = **rot * change;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -450,8 +450,7 @@ pub fn apply_input_to_player(
|
|||
(
|
||||
Entity,
|
||||
&mut actor::WantsAcceleration,
|
||||
&Rotation,
|
||||
Option<&mut actor::WantsRotation>,
|
||||
Option<&mut actor::WantsRotationChange>,
|
||||
),
|
||||
With<actor::PlayerCamera>,
|
||||
>,
|
||||
|
@ -463,7 +462,7 @@ pub fn apply_input_to_player(
|
|||
if player.is_err() {
|
||||
return;
|
||||
}
|
||||
let (entity, mut accel, rot, setrot) = player.unwrap();
|
||||
let (entity, mut accel, rot_change) = player.unwrap();
|
||||
|
||||
let (win_res_x, win_res_y): (f32, f32);
|
||||
if let Ok(window) = &q_windows.get_single() {
|
||||
|
@ -491,24 +490,18 @@ pub fn apply_input_to_player(
|
|||
|
||||
// Apply rotation to player
|
||||
if pitch_yaw_rot != Vec3::ZERO {
|
||||
let rot_offset = DQuat::from_euler(
|
||||
EulerRot::XYZ,
|
||||
pitch_yaw_rot[0] as f64,
|
||||
pitch_yaw_rot[1] as f64,
|
||||
pitch_yaw_rot[2] as f64,
|
||||
);
|
||||
let rot_current = if let Some(setrot) = &setrot {
|
||||
setrot.0
|
||||
let rot_change_current = if let Some(rot_change) = &rot_change {
|
||||
rot_change.0
|
||||
} else {
|
||||
**rot
|
||||
Vec3::ZERO
|
||||
};
|
||||
let rot_target = rot_current * rot_offset;
|
||||
if let Some(mut setrot) = setrot {
|
||||
setrot.0 = rot_target;
|
||||
let rot_target = rot_change_current + pitch_yaw_rot;
|
||||
if let Some(mut rot_change) = rot_change {
|
||||
rot_change.0 = rot_target;
|
||||
} else {
|
||||
commands
|
||||
.entity(entity)
|
||||
.try_insert(actor::WantsRotation(rot_target));
|
||||
.try_insert(actor::WantsRotationChange(rot_target));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue