summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-03-21 11:25:41 +0100
committerGitHub <noreply@github.com>2022-03-21 11:25:41 +0100
commit600ff3a22156a1b65916f6396814005eff6eb7ce (patch)
treee856139cb400bb79c808bacb488a7907dd7a8159
parent49176bc0fca3341a13a6919210999af16d686313 (diff)
parent234637ab79cd37409fc0d8c617e0ced463d1a34b (diff)
Merge pull request #48310 from Blackiris/fix-create-skeleton-physical-bones-4.0
-rw-r--r--editor/plugins/skeleton_3d_editor_plugin.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp
index ef171e9115..065683d632 100644
--- a/editor/plugins/skeleton_3d_editor_plugin.cpp
+++ b/editor/plugins/skeleton_3d_editor_plugin.cpp
@@ -419,8 +419,14 @@ PhysicalBone3D *Skeleton3DEditor::create_physical_bone(int bone_id, int bone_chi
capsule_transform.basis = Basis(Vector3(1, 0, 0), Vector3(0, 0, 1), Vector3(0, -1, 0));
bone_shape->set_transform(capsule_transform);
+ /// Get an up vector not collinear with child rest origin
+ Vector3 up = Vector3(0, 1, 0);
+ if (up.cross(child_rest.origin).is_equal_approx(Vector3())) {
+ up = Vector3(0, 0, 1);
+ }
+
Transform3D body_transform;
- body_transform.basis = Basis::looking_at(child_rest.origin);
+ body_transform.basis = Basis::looking_at(child_rest.origin, up);
body_transform.origin = body_transform.basis.xform(Vector3(0, 0, -half_height));
Transform3D joint_transform;