summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-04-30 12:09:45 +0200
committerGitHub <noreply@github.com>2019-04-30 12:09:45 +0200
commit712b789dc83f1d6e9279aa7c9368e6dc3ee7a21e (patch)
treec7273ad5d8a38e696e3afc2d4c91fe477c1f9159
parent419022ea8909f26ac4353cc816c553ca14e0b925 (diff)
parent9742d0c323a441036ee7753b85737aa8051714b3 (diff)
Merge pull request #26897 from rodolforg/fix_spatial_look_at_affecting_scale
Spatial::look_at() now preserves its scale values
-rw-r--r--scene/3d/spatial.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp
index 395f7b9b35..05fd984f93 100644
--- a/scene/3d/spatial.cpp
+++ b/scene/3d/spatial.cpp
@@ -676,8 +676,7 @@ void Spatial::set_identity() {
void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) {
- Transform lookat;
- lookat.origin = get_global_transform().origin;
+ Transform lookat(get_global_transform());
if (lookat.origin == p_target) {
ERR_EXPLAIN("Node origin and target are in the same position, look_at() failed");
ERR_FAIL();
@@ -687,7 +686,10 @@ void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) {
ERR_EXPLAIN("Up vector and direction between node origin and target are aligned, look_at() failed");
ERR_FAIL();
}
+ Vector3 original_scale(lookat.basis.get_scale());
lookat = lookat.looking_at(p_target, p_up);
+ // as basis was normalized, we just need to apply original scale back
+ lookat.basis.scale(original_scale);
set_global_transform(lookat);
}