Added overhead aiming camera

This commit is contained in:
Joshua Barretto 2020-05-19 14:26:53 +01:00
parent 2f47d09af4
commit 05e6df1b65
2 changed files with 17 additions and 11 deletions

View File

@ -78,6 +78,7 @@ pub struct SceneData<'a> {
pub mouse_smoothing: bool,
pub sprite_render_distance: f32,
pub figure_lod_render_distance: f32,
pub is_aiming: bool,
}
impl Scene {
@ -236,6 +237,7 @@ impl Scene {
player_scale * 1.65
}
},
CameraMode::ThirdPerson if scene_data.is_aiming => 2.1,
CameraMode::ThirdPerson => 1.65,
};

View File

@ -166,6 +166,18 @@ impl PlayState for SessionState {
_ => cam_pos, // Should never happen, but a safe fallback
};
let (is_aiming, aim_dir_offset) = {
let client = self.client.borrow();
let is_aiming = client
.state()
.read_storage::<comp::CharacterState>()
.get(client.entity())
.map(|cs| cs.is_aimed())
.unwrap_or(false);
(is_aiming, if is_aiming { Vec3::unit_z() * 0.025 } else { Vec3::zero() })
};
let cam_dir: Vec3<f32> = Vec3::from(view_mat.inverted() * -Vec4::unit_z());
// Check to see whether we're aiming at anything
@ -435,7 +447,7 @@ impl PlayState for SessionState {
if !free_look {
ori = self.scene.camera().get_orientation();
self.inputs.look_dir = Dir::from_unnormalized(cam_dir).unwrap();
self.inputs.look_dir = Dir::from_unnormalized(cam_dir + aim_dir_offset).unwrap();
}
// Calculate the movement input vector of the player from the current key
// presses and the camera direction.
@ -512,16 +524,7 @@ impl PlayState for SessionState {
&self.scene.camera(),
clock.get_last_delta(),
HudInfo {
is_aiming: {
let client = self.client.borrow();
let aimed = client
.state()
.read_storage::<comp::CharacterState>()
.get(client.entity())
.map(|cs| cs.is_aimed())
.unwrap_or(false);
aimed
},
is_aiming,
is_first_person: matches!(
self.scene.camera().get_mode(),
camera::CameraMode::FirstPerson
@ -753,6 +756,7 @@ impl PlayState for SessionState {
.graphics
.figure_lod_render_distance
as f32,
is_aiming,
};
// Runs if either in a multiplayer server or the singleplayer server is unpaused