B:BD[
3.8746] → [
3.8746:9037]
B:BD[
3.9037] → [
4.2876:3165]
∅:D[
4.3165] → [
3.9194:9289]
B:BD[
3.9194] → [
3.9194:9289]
match (player.get_single(), camera.get_single_mut()) {
(Ok(transform), Ok((mut camera, cam_transform))) => {
// Lerp the camera to player's global translation point
let source = cam_transform.translation();
let goal = transform.translation();
let adjusted_lag = rig.lag;
let lerped = source * adjusted_lag + goal * (1.0 - adjusted_lag);
let lerp_delta = lerped - source;
camera.subpixel_pos +=
lerp_delta.xy() * time.delta_seconds() / rig.snap_duration.as_secs_f32();
}
_ => {
// Either the camera or the player doesnt exist
}
// This is only 1 camera...
let (mut camera, cam, cam_transform) = camera.single_mut();
// ...but soooo many targets
let targeted = targets
.iter()
.filter(|(_, t)| t.0 == cam.targetting)
.collect::<Vec<_>>();
// Get the midpoint of all targeted items
let goal = targeted
.iter()
.map(|(transform, _)| transform.translation())
.reduce(|total, e| total + e)
.map(|total| total / targeted.len() as f32);
if let Some(goal) = goal {
// Lerp the camera to player's global translation point
let source = cam_transform.translation();
// Taken from https://mastodon.social/@acegikmo/111931613710775864
let lambda = -rig.snap_duration.as_secs_f32() / rig.precision.log2();
let alpha = 2.0f32.powf(-time.delta_seconds() / lambda);
let lerped = source * alpha + goal * (1.0 - alpha);
camera.subpixel_pos = lerped.xy();