fix camera angles to prevent char from disappearing
This commit is contained in:
@@ -30,12 +30,17 @@ struct CameraUi;
|
||||
pub struct MainCamera {
|
||||
dir: Dir3,
|
||||
distance: f32,
|
||||
target_offset: Vec3,
|
||||
}
|
||||
|
||||
impl MainCamera {
|
||||
fn new(arm: Vec3) -> Self {
|
||||
let (dir, distance) = Dir3::new_and_length(arm).expect("invalid arm length");
|
||||
Self { dir, distance }
|
||||
Self {
|
||||
dir,
|
||||
distance,
|
||||
target_offset: Vec3::new(0., 2., 0.),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +62,7 @@ pub fn plugin(app: &mut App) {
|
||||
fn startup(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Camera3d::default(),
|
||||
MainCamera::new(Vec3::new(0., 2.5, -13.)),
|
||||
MainCamera::new(Vec3::new(0., 1.8, -15.)),
|
||||
CameraRotationInput::default(),
|
||||
));
|
||||
}
|
||||
@@ -120,14 +125,14 @@ fn update(
|
||||
return;
|
||||
}
|
||||
|
||||
let target = target_q.translation;
|
||||
|
||||
let arm_tf = arm_rotation;
|
||||
|
||||
let Ok((camera, mut cam_transform, cam_rotation_input)) = cam.single_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let target = target_q.translation + camera.target_offset;
|
||||
|
||||
let direction = arm_tf.rotation * Quat::from_rotation_y(cam_rotation_input.x) * camera.dir;
|
||||
|
||||
let max_distance = camera.distance;
|
||||
|
||||
Reference in New Issue
Block a user