Skip to content

Commit

Permalink
offset
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienjuif committed Nov 23, 2023
1 parent 445d635 commit 2608bfe
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions camera/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ fn cameraman(
// TODO: for now we follow the first target but we could think of doing an average positions of all the targets
if camera.target == target_entity {
let diff = camera_transform.translation - target_transform.translation;
let diff = diff.abs();
let diff_abs = diff.abs();

if diff.x > camera.offset.x {
camera_transform.translation.x = target_transform.translation.x;
if diff_abs.x > camera.offset.x {
camera_transform.translation.x = target_transform.translation.x
- if diff.x > 0. {
-camera.offset.x
} else {
camera.offset.x
};
}
if diff.y > camera.offset.y {
camera_transform.translation.y = target_transform.translation.y;
if diff_abs.y > camera.offset.y {
camera_transform.translation.y = target_transform.translation.y
- if diff.y > 0. {
-camera.offset.y
} else {
camera.offset.y
};
}

break;
Expand Down

0 comments on commit 2608bfe

Please sign in to comment.