Skip to content

Commit

Permalink
Fix look_to variable naming (#8627)
Browse files Browse the repository at this point in the history
# Objective

- If I understand correctly, forward points in `direction`, so the
negative of `direction` should be back.

## Migration Guide

- `Transform::look_to` method changed default value of
`direction.try_normalize()` from `Vec3::Z` to `Vec3::NEG_Z`
  • Loading branch information
lewiszlw authored May 23, 2023
1 parent ebac7e8 commit df3e81c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,19 @@ impl Transform {
/// and [`Transform::up`] points towards `up`.
///
/// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases:
/// * if `direction` is zero, `Vec3::Z` is used instead
/// * if `direction` is zero, `Vec3::NEG_Z` is used instead
/// * if `up` is zero, `Vec3::Y` is used instead
/// * if `direction` is parallel with `up`, an orthogonal vector is used as the "right" direction
#[inline]
pub fn look_to(&mut self, direction: Vec3, up: Vec3) {
let forward = -direction.try_normalize().unwrap_or(Vec3::Z);
let back = -direction.try_normalize().unwrap_or(Vec3::NEG_Z);
let up = up.try_normalize().unwrap_or(Vec3::Y);
let right = up
.cross(forward)
.cross(back)
.try_normalize()
.unwrap_or_else(|| up.any_orthonormal_vector());
let up = forward.cross(right);
self.rotation = Quat::from_mat3(&Mat3::from_cols(right, up, forward));
let up = back.cross(right);
self.rotation = Quat::from_mat3(&Mat3::from_cols(right, up, back));
}

/// Multiplies `self` with `transform` component by component, returning the
Expand Down

0 comments on commit df3e81c

Please sign in to comment.