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_physics_lifeforms.run_if(game_running),
|
||||||
update_power.run_if(game_running),
|
update_power.run_if(game_running),
|
||||||
handle_gravity.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_acceleration.run_if(game_running).run_if(alive),
|
||||||
handle_wants_maxrotation.run_if(game_running),
|
handle_wants_maxrotation.run_if(game_running),
|
||||||
handle_wants_maxvelocity
|
handle_wants_maxvelocity
|
||||||
|
@ -185,7 +185,7 @@ pub struct WantsMaxVelocity(pub f64);
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct WantsToLookAt(pub String);
|
pub struct WantsToLookAt(pub String);
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct WantsRotation(pub DQuat);
|
pub struct WantsRotationChange(pub Vec3); // Vec3 = (pitch, yaw, rot)
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct WantsMatchVelocityWith(pub String);
|
pub struct WantsMatchVelocityWith(pub String);
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
@ -586,6 +586,7 @@ pub fn handle_vehicle_enter_exit(
|
||||||
*driver_vis = Visibility::Hidden; //seems to have no effect...
|
*driver_vis = Visibility::Hidden; //seems to have no effect...
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::EnterVehicle));
|
||||||
commands.entity(driver).remove::<PlayerCamera>();
|
commands.entity(driver).remove::<PlayerCamera>();
|
||||||
|
commands.entity(driver).remove::<WantsRotationChange>();
|
||||||
commands.entity(driver).remove::<Collider>();
|
commands.entity(driver).remove::<Collider>();
|
||||||
commands.entity(driver).insert(JustNowEnteredVehicle);
|
commands.entity(driver).insert(JustNowEnteredVehicle);
|
||||||
commands
|
commands
|
||||||
|
@ -717,9 +718,27 @@ fn handle_wants_maxvelocity(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_wants_rotation(mut q_actor: Query<(&mut Rotation, &WantsRotation)>) {
|
fn handle_wants_rotation_change(mut q_actor: Query<(&mut Rotation, &mut WantsRotationChange)>) {
|
||||||
for (mut rot, setrot) in &mut q_actor {
|
for (mut rot, mut change_rot) in &mut q_actor {
|
||||||
**rot = setrot.0;
|
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,
|
Entity,
|
||||||
&mut actor::WantsAcceleration,
|
&mut actor::WantsAcceleration,
|
||||||
&Rotation,
|
Option<&mut actor::WantsRotationChange>,
|
||||||
Option<&mut actor::WantsRotation>,
|
|
||||||
),
|
),
|
||||||
With<actor::PlayerCamera>,
|
With<actor::PlayerCamera>,
|
||||||
>,
|
>,
|
||||||
|
@ -463,7 +462,7 @@ pub fn apply_input_to_player(
|
||||||
if player.is_err() {
|
if player.is_err() {
|
||||||
return;
|
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);
|
let (win_res_x, win_res_y): (f32, f32);
|
||||||
if let Ok(window) = &q_windows.get_single() {
|
if let Ok(window) = &q_windows.get_single() {
|
||||||
|
@ -491,24 +490,18 @@ pub fn apply_input_to_player(
|
||||||
|
|
||||||
// Apply rotation to player
|
// Apply rotation to player
|
||||||
if pitch_yaw_rot != Vec3::ZERO {
|
if pitch_yaw_rot != Vec3::ZERO {
|
||||||
let rot_offset = DQuat::from_euler(
|
let rot_change_current = if let Some(rot_change) = &rot_change {
|
||||||
EulerRot::XYZ,
|
rot_change.0
|
||||||
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
|
|
||||||
} else {
|
} else {
|
||||||
**rot
|
Vec3::ZERO
|
||||||
};
|
};
|
||||||
let rot_target = rot_current * rot_offset;
|
let rot_target = rot_change_current + pitch_yaw_rot;
|
||||||
if let Some(mut setrot) = setrot {
|
if let Some(mut rot_change) = rot_change {
|
||||||
setrot.0 = rot_target;
|
rot_change.0 = rot_target;
|
||||||
} else {
|
} else {
|
||||||
commands
|
commands
|
||||||
.entity(entity)
|
.entity(entity)
|
||||||
.try_insert(actor::WantsRotation(rot_target));
|
.try_insert(actor::WantsRotationChange(rot_target));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue